|
Is there any difference between:
if foo is None: pass
and
if foo == None: pass
The convention that I've seen in most Python code (and the code I myself write) is the former, but I recently came across code which uses the latter. None is an instance (and...
Started by Joe Shaw on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
The NoneType probably returns identity....
For None there shouldn't be a difference between equality (==) and identity (is).
Gt;> f = foo() >>> f == None True >>> f is None False
You may want to read (same value).
|
|
I need to return values, and when someone asks for a value, tell them one of three things:
Here is the value There is no value We have no information on this value (unknown) case 2 is subtly different than case 3. Example:
val radio = car.radioType
we...
Started by Alex Black on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
Pioneer")) hasValue: Result = Right(Some(pioneer)) scala> val noValue: Result = Right(None) noValue: Result = Right(None) scala> val unknownValue = Left("unknown") unknownValue: Left[java.lang.String) case TriNone => println("....
|
|
I have a grid (6 rows, 5 columns):
grid = [ [None, None, None, None, None], [None, None, None, None, None], [None, None, None, None, None], [None, None, None, None, None], [None, None, None, None, None], [None, None, None, None, None], ]
I augment the...
Started by Matt on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
Is not None for n in x)] # remove empty columns if not grid: raise ValueError("empty grid for r in grid: empties = [c for c in empties if r[c] is None] # strip out non-empty if empties(removeBlankRows(transpose(grid))))
Output:
[[{'some....
|
Ask your Facebook Friends
|
Most concise way to check whether a list is empty or [None]?
I understand that I can test:
if MyList: pass
and:
if not MyList: pass
but what if the list has an item (or multiple items), but those item/s are None:
MyList = [None, None, None] if ???: pass...
Started by Phillip Oldham on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
If you are concerned with elements in the list which evaluate as true:
if mylist and filter(None, or it contains no true values"
If you want to strictly check for None , use filter(lambda x: x is not None, mylist) instead of filter....
|
|
Is there a Python built-in datatype, besides None , for which:
>>> not foo > None True
where foo is a value of that type? How about Python 3?
Started by Attila Oláh on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
None < None....
Thus, expressions like 1 < '', 0 > None or len <= len are no longer valid, and e.g.
In Python 3, this was changed; now doing a meaningful natural ordering .
None is always less than any datatype in Python 2.
|
|
Is there any clever in-built function or something that will return 1 for the min() example below? (I bet there is a solid reason for it not to return anything, but in my particular case I need it to disregard None values really bad!)
>>> max...
Started by c00kiemonster on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
None is being returned
>>> print min([None, 1,2]) None >>> None < 1 True
If you want to return 1 you have to filter the None away:
>>> L = [None, 1, 2] >>> min(x for x in....
|
|
I am trying to translate the following code
d = {} d[0] = None
into C++ with boost.python
boost::python::dict d; d[0] = ?None
How can I get a None object in boost.python?
ANSWER:
boost::python::dict d; d[0] = boost::python::object();
Started by Dzhelil Rufat on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
You could use:
d[0] = d.get(0)
d.get defaults to None if you don't specify a default value managing a reference to the Python None object..
|
|
I have tried this
login_div.Style("display") = "none";
But it's not working.how can I set the display of the div to none through code behind, in aspx I have a div:
<div id="login_div" runat="server">
Started by sumit on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
I believe this should work:
login_div.Attributes.Add("style","display:none");
Style is a collection of name-value pairs so you would set it as:
login_div.Style["display"] = "none";
(Square brackets="display:none;">Content</....
|
|
Basically I have some variables that I don't want to preinitialize:
originalTime = None recentTime = None postTime = None def DoSomething ( ) : if originalTime == None or (postTime - recentTime).seconds > 5 : ...
I get compile error on the if:
UnboundLocalError...
Started by Joan Venge on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
Also it's a bit better to say originalTime is None a function, but the = None declarations are at the module-level, then the variables are out of scope an object:
class SomeTimeClass....
A function but originalTime is defined somewhere else.
|
|
How is
<None Include="C:\foo.bar" />
different from
<Content Include="C:\foo.bar" />
?
Thanks
Started by Emmett on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
None - The file is not included in the project.
One difference is how they get published; "None" items don't get included in a publish, "Content on the build action property explains the differences.
|