[Tutor] Your dog Scope bit me!

fleet@teachout.org fleet@teachout.org
Mon, 20 Aug 2001 23:16:45 -0400 (EDT)


I'm trying to create a function that will retrieve a pickled dictionary.
Python doesn't complain about the following; but I don't "get" anything
and no "upc" is listed in dir().

def get_upc():
   """retrieves upc dictionary as upc"""
   import pickle
   f=open("upc.dict")
   upc=pickle.load(f)
   f.close()
   print "UPC Dictionary retrieved"

I'm assuming I have a scope problem.  Guess I don't understand all I
should about scopes.  How do I run this from an interactive session so
that I'm able to use the dictionary?

Entering each of the lines in an interactive session retrieves the
dictionary; but then I'm not in the "scope" of the function.

				- fleet -