Mucking with the calling scripts namespace (For a good reason, honest!)
From: Doug Rosser (da_rosser_at_yahoo.com)
Date: 08/02/04
- Next message: Tim Williams: "Re: Trimming a string"
- Previous message: Roy Smith: "Re: Strange timing data for list.pop()"
- Next in thread: Larry Bates: "Re: Mucking with the calling scripts namespace (For a good reason, honest!)"
- Reply: Larry Bates: "Re: Mucking with the calling scripts namespace (For a good reason, honest!)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 2 Aug 2004 08:27:35 -0700
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 --
- Next message: Tim Williams: "Re: Trimming a string"
- Previous message: Roy Smith: "Re: Strange timing data for list.pop()"
- Next in thread: Larry Bates: "Re: Mucking with the calling scripts namespace (For a good reason, honest!)"
- Reply: Larry Bates: "Re: Mucking with the calling scripts namespace (For a good reason, honest!)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|