Newbie Variable Definition Question

Andrew N. McGuire amcguire at coastalnet.com
Tue Dec 14 11:03:29 EST 1999


Hey all,

    I am a python newbie and am picking up on it very quickly.
Python seems to be a remarkably simple language to learn, however
I have one question..

   This is primarily oriented towards the *nix guys out there....
In Bourne / Korn / Bash shells there is the syntax...

    if [ $variable = "" ]; then
        commands
    fi

   This tests if a variable is defined, and if not, execute commands.
Also there is the following statement as well....

    variable=${variable:=value}

   This checks if variable is defined and if not, it assigns it a value
of "value".
I was wondering if there was a way to check if a variable is assigned by
referencing its
name in python, even if there is a chance that it is not defined....
All
my attempts lead to NameError, perhaps this can be used, but I have not
figured
out how to keep the script from stopping after the NameError error.

Any help is greatly appreciated, and thanks in advance.

Regards,

Andrew N. McGuire
UNIX System Administrator




More information about the Python-list mailing list