How to check whether a variable is defined earlier in a program?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bharathpaul
    New Member
    • Mar 2010
    • 6

    How to check whether a variable is defined earlier in a program?

    Hi,
    I am using Python 3.1.1. In perl we can use defined($variab le name) to check whether a variable is defined previously or not.. I am looking for a function in Python which is used to check whether a Dictionary is defined previously.
    Note:
    I tried with not Operator which is not at all helpful.
  • Glenton
    Recognized Expert Contributor
    • Nov 2008
    • 391

    #2
    Recipe for testing is a variable is defined.

    Generally, in python the variable is assumed to be defined. Perhaps you can tell us what you're trying to do, and we'll help find a pythonic way of doing it?

    Good luck!

    Comment

    • bharathpaul
      New Member
      • Mar 2010
      • 6

      #3
      Actually i am comparing the perl code with python. In Perl, they can define the variable in anyplace and can use undef to undefine a variable. I just want to know, is there a similar kind of things are in python..

      Comment

      • Glenton
        Recognized Expert Contributor
        • Nov 2008
        • 391

        #4
        Python tends to do things slightly differently. But my experience on perl is pretty small...

        Comment

        Working...