creating variable in root namespace from module

MakaMaka justin.frost at gmail.com
Fri Mar 10 11:56:52 EST 2006


Hi again,
Steve-
I'm trying to use python to model reliability.  Basically, I want to
read an XML file in that defines a bunch of variables, that are then
accessible from the python interpreter.  For example:
import reliability

reliability.read_xml("c:\\somefile.xml") #<== defines x1, x2, x3

result = x1+x2+x3

This tool will be used by people who are not necessarily coders and I
don't want them to have to deal with passing global namespaces etc.

Duncan-
I like your idea; however, I don't want the user to actually have to
know the structure of the xml file, so I don't think I can do it this
way.  There might be 3, 4 or 1000 variables that the function needs to
create.

Any other ideas?  What clever technical ways have been used? I know I
can just have the function add the variables to the global namespace of
the module and then access them like

reliability.x1

or in a dict or something, but I think this might confuse some of my
potential users who aren't familiar with Object Oriented programming
(think electrical engineers who still code in Fortran).

Thanks,
Justin




More information about the Python-list mailing list