How to import whole namespace into global symbol table? (newbie)

Scott Simpson ssimpson at interchangeusa.com
Thu Apr 27 19:52:54 EDT 2006


Suppose I have the following python program:

def func():
     from sys import stderr, exit
     try:
         f = open("foo", 'r')
     except IOError:
         print >> stderr, "Input file foo does not exist"
         exit(1)

def main():
     import sys

     if len(args) != 0:
         sys.exit(1)

     func()

if __name__ == '__main__':
     main()

Notice that I have two "import sys" statements, one for each function. 
Is there any way to import the "sys" stuff to the global symbol table so 
I don't need two "import" statements?

Lastly, is there an equivalent of Perl's "die" function? I'm writing to 
stderr and dieing above but I'm not quite sure if this is the "correct" way.



More information about the Python-list mailing list