How to get two modules loaded into the same namespace?

r.vanwees at r.vanwees at
Thu Nov 8 17:06:40 CET 2001

I am trying to build a rule engine. I have two Python modules: and

I want to keep the engine and the utility functions separated for 
reasons of maintainiability and cleannes.

I am running into a few problems:

1) In I have defined a global, DEBUG_PRINT_LEVEL, which 
allows me to steer the amount of debug info I get at runtime 
(curently somewhere between 'nothing' and 'an awful lot').

When I try the following in

    from utilities import *

    class RuleEngine:

I get a NameError on DEBUG_PRINT_LEVEL (see stack trace below):

    File "D:\Dev\PyCharGen\", line 120, in calcLevel
    if DEBUG_PRINT_LEVEL >= 4:
    NameError: global name 'DEBUG_PRINT_LEVEL' is not defined
    Process terminated with exit code 0

As far as I understand the 
docs, the 'from x import *' syntax should import stuff into the 
current namespace, but apparently this does not hold for globals.

2) Several functions in refer back to functions in They also return a NameError (see stacktrace below 
from an actual debug log)

    File "D:\Dev\PyCharGen\", line 157, in calcSpells
    statLevel = find(stat, 'base') + find(stat, 'bonus')
    NameError: global name 'find' is not defined
    Process terminated with exit code 0

Again, it seems that the two modules are not in the same namespace.

Both python 2.1.1 and 2.2beta show this behavior.

Does anyone know a solution (other than putting the utility functions 
in to this problem? I must admit that I got lost at 
the Python namespace rules before...

Kind regards,

Rob van Wees

More information about the Python-list mailing list