Re: How can I tell if variable is defined

2009-09-22 Thread Dave Angel
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.

Re: How can I tell if variable is defined

2009-09-22 Thread Mel
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.

Re: How can I tell if variable is defined

2009-09-22 Thread Peter Otten
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

Re: How can I tell if variable is defined

2009-09-22 Thread Peter Otten
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

Re: How can I tell if variable is defined

2009-09-22 Thread Mel
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

Re: How can I tell if variable is defined

2009-09-22 Thread Dave Angel
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

Re: How can I tell if variable is defined

2009-09-22 Thread Grant Edwards
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

Re: How can I tell if variable is defined

2009-09-22 Thread Rami Chowdhury
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

Re: How can I tell if variable is defined

2009-09-22 Thread Sean DiZazzo
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 can I tell if variable is defined

2009-09-22 Thread Brown, Rodrick
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