Python newbie needs help

Dennis Benzinger Dennis.Benzinger at
Wed Dec 14 20:40:51 CET 2005

Ron Hudson schrieb:
> [...]
> I have a .py file with some def scripts(?) in it. 

def is the begining of a function definition.

> [...]
> I am using "Import" to read it after I start an interactive python.  
> What I need
> right now is I seem to have some sort of scoping problems with the  
> world dictionary.
> I can read it and write it and "world<cr>" lists it out. but my def  
> look(at): script
> it seems it doesn't see the the "world" dictionary.
>  >>> import lets
>  >>> world = lets.loadworld()
>  >>> world
> {'wizarddescription':'A short guy wearing a robe and a pointy hat'}
>  >>> lets.look('wizard')
>      file "<stdin>" line ?
>      file line 14 in look
>         print world[at+'description']
> nameError:world
>  >>> at = 'wizard'
>  >>> print world[at+'description']
> A short guy wearing a robe and a pointy hat
>  >>>
> Is there a way to make 'world' global? can I do it in
> Am I going about this all wrong?
> [...]

The easiest solution for you would be a world variable in your lets 
module. Then at the interactive prompt you could refer to it with So the loadworld function in would look like this:

def loadworld():
     # Your loading code
     global world
     world = ...


More information about the Python-list mailing list