Mucking with the calling scripts namespace (For a good reason, honest!)

Doug Rosser da_rosser at yahoo.com
Mon Aug 2 17:27:35 CEST 2004


I'm writing a fairly complicated test framework and keeping
configuration data inside ini files that are parsed at runtime by the
ConfigParser module.

For example, there would be a section similar to the following

[servers]
server1:{'hostname':'alpha','os':'posix'}
server2:{'hostname':'beta','os':'win'}

[clients]
client1:{'hostname':'ichi','os':'posix'}
client2:{'hostname':'ni','os':'posix'}

As I read the configuration file, I don't actually create instances,
but use the data to check "what's out there" to make sure the physical
network environment has the bits and pieces required to run a
particular test. This is a sort of "go/no-go" resource check.

Assuming that everything is correct with the physical network
environment, I want my testers to be able to refer to these resources
in their python scripts by the names in the ini file, like so:

myTest.checkResources() # Read the config file and associate names
with real
                        # life instances

server1.doSomething()   # Note how I have cleverly saved myself from
declaring
                        # "server1" because the module myTest has
inserted
                        # it into the right namespace :-)

Down to business: How do I write a module that can insert these names
into the calling script's namespace at runtime? Is this even possible
in Python?

da rosser
-- We are the music makers, and we are the dreamers of dreams --



More information about the Python-list mailing list