Help on scope/namespace

Byron Morgan lazypointer at yahoo.com
Sun Feb 2 04:48:12 CET 2003


Well, I've gotten far enough into my first Python project that I would like
to split up the source. From the start, I built a library of dictionaries,
which I import at runtime, and this works fine. I discovered that if I
wanted to change a variable declared outsid a fuction, I had to declare it
as 'global' with the function.

I have nearly 100 functions that I'd like to import, rather than maintaining
them in the main script. I tried putting them into their own file, but they
couldn't see the objects  (dictionaries & lists) that were loaded from the
first file. So I tried putting them in the same file, but this didn't work
either. So I made a class with all the functions inside, still no go.

It's not that I haven't read the documentation on namespaces and scoping: it
just seems like doubletalk to me.

Is there some way I can import functions from a file, and have them behave
just as though they are contained in the main script ?

Byron Morgan






More information about the Python-list mailing list