Check undefined variable
Chris Gonnerman
chris.gonnerman at newcenturycomputers.net
Tue Jul 30 11:37:59 EDT 2002
On Tue, 30 Jul 2002 09:24:57 -0600, Daniel Fackrell wrote:
> "Michael Grabietz" <michael.grabietz at img-online.de> wrote in message
> news:3D46AD2E.709 at img-online.de...
> > how is it possible to check whether a variable 'a' is undefined or not.
> >
> > e.g.:
> >
> > if a==NULL : # something like that
> > print 'a is undefined !'
> > else
> > print 'a already undefined !'
>
> try:
> type(A)
> print 'A exists'
> except NameError:
> print 'A doesn't exist'
Actually this works:
try:
A
print "A exists"
except NameError:
print "A doesn't exist"
in other words, just call out the name and see if it answers :-)
More information about the Python-list
mailing list