Check if variable is defined

Harald Kirsch kirschh at lionbioscience.com
Fri May 18 02:50:21 EDT 2001


"Fredrik Lundh" <fredrik at pythonware.com> writes:

> Todd A. Jacobs wrote:
> > I'm having a lot of trouble doing something that was simple in Perl:
> > specifically, I want to create if/else clauses that take action only if a
> > particular variable is undefined. How do I check to see if a variable or
> > object has already been defined?
> 
> that's extremely bad style in Python, but you probably knew that.

If that were true, it would declare a lot of interesting applications
for Python in particular and script languages in general as `bad
style' a priori.

In these applications you define little languages for users which are
not really programmers, but for whom you want to provide a way to hack
in some simple commands for a dedicated task. Instead of writing a
parser you define these commands as Python functions at let the basic
syntax be Python --- why not, it is as good or even better as any
ad-hoc invented one.

After execfile()-ing their command file it *is* often necessary to
test if certain variables where set or not --- of course depending on
how you defined your little language.


  Harald Kirsch

P.S.: I feel like starting a flame war today which is why I would like
to maintain that little languages are easier to do in Tcl ;-)

-- 
----------------+------------------------------------------------------
Harald Kirsch   | kirschh at lionbioscience.com | "How old is the epsilon?"
LION bioscience | +49 6221 4038 172          |        -- Paul Erdös
       *** Please do not send me copies of your posts. ***



More information about the Python-list mailing list