Question regarding indirect function calls

Maxwell Hammer hammer at maxwell.com
Mon Apr 14 05:01:21 CEST 2003


In reply to: Jack & Alex:

Thanks for your advice, I did get it working using "getattr" as you
suggested.

Great! now I have another questions, since I have your attention :-)

What is the most efficient way of accessing global variables across
modules?

I have main.py which parses a config file and sets up config values
appropriately. Different values are required by different functions in
other modules.

I have tried defining the config values as global in main, AND in the
other modules - but does not work (get undefine errors).
main.py:
  global config_values
  config_values = []
...
 load config_values
...

Module x
 global config_values

def function1():
  try to access config_values[0] fails - not found

So what I am currntly doing is passing what ever config values are needed
through the function call
  x.function1(config_values, etc)

How would you do this??

Once again thanks for help with indirect calls.





More information about the Python-list mailing list