[Tutor] testing for variable creation?

Gus Tabares gus.tabares@verizon.net
Sun Jun 8 21:32:01 2003


Thomas,

	I think what you're looking for involves using the built-in function 'dir'.
For example:

>>> x = 5
>>> dir()
['__builtins__', '__doc__', '__name__', 'x']

I believe it returns a list of the variables in that namespace.


HTH,
Gus

-----Original Message-----
From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
Thomas CLive Richards
Sent: Sunday, June 08, 2003 8:25 PM
To: tutor@python.org
Subject: [Tutor] testing for variable creation?



Hey,


Is there an easy way to test to see if a specific variable has been
created yet?

I know you can use try: and except:, but surely there's an easier
solution? (i seem to remember reading somewhere about a dictionary which
stored references to all the variables inside a script??)

any ideas?


thanks,

--

Thomi Richards,
thomi@thomi.imail.net.nz


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor