reference

Python - how to check if weak reference is still available

心不动则不痛 提交于 2019-12-22 06:57:02
问题 I am passing some weakrefs from Python into C++ class, but C++ destructors are actively trying to access the ref when the real object is already dead, obviously it crashes... Is there any Python C/API approach to find out if Python reference is still alive or any other known workaround for this ? Thanks 回答1: If you call PyWeakref_GetObject on the weak reference it should return either Py_None or NULL, I forget which. But you should check if it's returning one of those and that will tell you

Change class of variables in a data frame using another reference data frame

安稳与你 提交于 2019-12-22 06:56:29
问题 I was looking for some way to change class of variables in one data frame by using the reference of another data frame which has information of class for each variable. I have a data which contains around 150 variables. All the variables are in character format. Now I want to change the class of each variable depending upon its type. For this we created a separate data frame having information of class for each of the variables. Let me explain with an sample data frame. Consider my original

Is passing variables by reference deprecated?

折月煮酒 提交于 2019-12-22 06:53:02
问题 There is a comment on an answer on SO: Code in answer: $larry = & $fred; Comment: This is deprecated and generates a warning But I don't think it is correct. Or is it? So basically the question is: can I copy a variable to another variable by reference? 回答1: Depends on what type variable $fred is. If it's an object, it will be passed as reference a pointer to the object (thanks NikiC) will be passed as value anyway as of PHP 5, so there is no need to explicitly do it. Thus far, the comment is

An unusual Python syntax element frequently used in Matplotlib

≯℡__Kan透↙ 提交于 2019-12-22 06:08:09
问题 One proviso: The syntax element at the heart of my Question is in the Python language; however, this element appears frequently in the Matplotlib library, which is the only context i have seen it. So whether it's a general Python syntax question or a library-specific one, i am not sure. What i do know is that i could not find anything on point--either in the Python Language Reference or in the Matplotlib docs. Those who use and/or develop with the excellent Python plotting library, Matplotlib

Function doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used

扶醉桌前 提交于 2019-12-22 06:01:36
问题 I'm getting this error: Function 'getkey' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used. to the following code: Public Function getkey(ByVal id As String) Dim cmd As SqlCommand Try cmd = New SqlCommand("dbo.getkeydesc", GenLog.cn) cmd.CommandType = CommandType.StoredProcedure cmd.Parameters.AddWithValue("@id", id) Dim r As SqlDataReader = cmd.ExecuteReader() If r.HasRows Then Return True Else Return False End If Catch ex

How to create a query for matching keys?

左心房为你撑大大i 提交于 2019-12-22 05:07:26
问题 I use the key of another User, the sponsor, to indicate who is the sponsor of a User and it creates a link in the datastore for those Users that have a sponsor and it can be at most one but a sponsor can sponsor many users like in this case ID 2002 who sponsored three other users: In this case this query does what I want: SELECT * FROM User where sponsor =KEY('agtzfmJuYW5vLXd3d3ILCxIEVXNlchjSDww') but I don't know how to program that with python, I can only use it to the datastore. How can I

How to create a query for matching keys?

与世无争的帅哥 提交于 2019-12-22 05:07:08
问题 I use the key of another User, the sponsor, to indicate who is the sponsor of a User and it creates a link in the datastore for those Users that have a sponsor and it can be at most one but a sponsor can sponsor many users like in this case ID 2002 who sponsored three other users: In this case this query does what I want: SELECT * FROM User where sponsor =KEY('agtzfmJuYW5vLXd3d3ILCxIEVXNlchjSDww') but I don't know how to program that with python, I can only use it to the datastore. How can I

Scala, Java and equality

假装没事ソ 提交于 2019-12-22 04:58:06
问题 val filesHere = (new java.io.File(".")).listFiles val filesHere2 = (new java.io.File(".")).listFiles scala> filesHere == filesHere2 res0: Boolean = false That is quite counter intuitive. I would rather expect that filesHere and filesHere2 are equal. This is certainly due to a semantics mismatch between Java and Scala, e.g., about arrays or (files) equality. Clearly, I am missing something here! 回答1: You may want to read through here: http://ofps.oreilly.com/titles/9780596155957

What is a direct reference?

巧了我就是萌 提交于 2019-12-22 04:56:35
问题 One of the strict mode rules (Annex C) states: When a delete operator occurs within strict mode code, a SyntaxError is thrown if its UnaryExpression is a direct reference to a variable, function argument, or function name. So in this code: delete x x is a reference. (I know this because "the result of evaluating an Identifier is always a value of type Reference"). But is it a direct reference? And, are there other kinds of references? Indirect references? (If not, what's the point of using

What is the difference between &Trait and impl Trait when used as method arguments?

旧时模样 提交于 2019-12-22 04:52:47
问题 In my project so far, I use many traits to permit mocking/stubbing in unit tests for injected dependencies. However, one detail of what I'm doing so far seems so suspicious that I'm surprised it even compiles. I'm worried that something dangerous is going on that I don't see or understand. It's based on the difference between these two method signatures: fn confirm<T>(subject: &MyTrait<T>) ... fn confirm<T>(subject: impl MyTrait<T>) ... I only just discovered the impl ... syntax in method