Mel wrote:
This is an artifact of the interactive interpreter,
True. You can avoid the artifact by wrapping the test in a function:
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Peter Otten wrote:
> Mel wrote:
>> Grant Edwards wrote:
>>> On 2009-09-22, Brown, Rodrick wrote:
>>>
How could I do the following check in Python
In Perl I could do something like if ((defined($a)) { ... }
>>>
[ ... ]
> This is an artifact of the interactive interpreter,
True.
Mel wrote:
> Grant Edwards wrote:
>
>> On 2009-09-22, Brown, Rodrick wrote:
>>
>>> How could I do the following check in Python
>>>
>>> In Perl I could do something like if ((defined($a)) { ... }
>>
>> try:
>> yourNameHere
>> except NameError:
>> print "undefined"
>> else:
>> print
Brown, Rodrick wrote:
> How could I do the following check in Python
>
> In Perl I could do something like if ((defined($a)) { ... }
>
> I tried if var is not None:
> However this doesn't seem to work as described.
But in Python this often is the most idiomatic way to check whether a
variable
Grant Edwards wrote:
> On 2009-09-22, Brown, Rodrick wrote:
>
>> How could I do the following check in Python
>>
>> In Perl I could do something like if ((defined($a)) { ... }
>
> try:
> yourNameHere
> except NameError:
> print "undefined"
> else:
> print "defined"
This being Pytho
Brown, Rodrick wrote:
How could I do the following check in Python
In Perl I could do something like if ((defined($a)) { ... }
I tried if var is not None:
However this doesn't seem to work as described.
Thanks.
try/except
Or look up the attribute in the appropriate dictionary(ies).
de
On 2009-09-22, Brown, Rodrick wrote:
> How could I do the following check in Python
>
> In Perl I could do something like if ((defined($a)) { ... }
try:
yourNameHere
except NameError:
print "undefined"
else:
print "defined"
> I tried if var is not None:
> However this doesn't seem t
On Tue, 22 Sep 2009 11:03:25 -0700, Brown, Rodrick
wrote:
How could I do the following check in Python
In Perl I could do something like if ((defined($a)) { ... }
I tried if var is not None:
However this doesn't seem to work as described.
Thanks.
Could you let us know in what context yo
On Sep 22, 11:03 am, "Brown, Rodrick " wrote:
> How could I do the following check in Python
>
> In Perl I could do something like if ((defined($a)) { ... }
>
> I tried if var is not None:
> However this doesn't seem to work as described.
>
> Thanks.
try:
var
except NameError:
handle_it()
How could I do the following check in Python
In Perl I could do something like if ((defined($a)) { ... }
I tried if var is not None:
However this doesn't seem to work as described.
Thanks.
--
http://mail.python.org/mailman/listinfo/python-list
10 matches
Mail list logo