On Mar 25, 2005, at 5:16 PM, [EMAIL PROTECTED] wrote:


For example I have a class named Indicators. If I cut it out and put it in a file call Ind.py then "from Ind import Indicators" the class can no longer see my globals. This is true even when the import occurs after the config file has been read and parsed.

I'm new enough at this myself so that (a) I understand how you get into this problematic situation and (b) you should take what I say with a spoon or two of salt.


I find it most useful to think of the problem as *getting rid of global variables*. (Compared with some other languages Python practically has no globals; module is the most global scope there is.) That means (1) designing some kind of clear and efficient package for data that you can pass back and forth between classes and modules; and (2) redesigning the classes themselves. The redesign is aimed at narrowing down how everything gets and sends data -- no more grabbing into the global air, but referring to some specific data package (which may be an instance of a special class).

The nice thing about this is that by implementing it, you're automatically greatly increasing the "object oriented" qualities of the program, with the consequent gains: modularity, clarity of interface . . . It tends to make the whole program's design clearer and clearer. So the rigors you go through in the redesign really pay off in your own understanding of your own program -- especially six months later.

I'm sure people who know a lot better what they're talking about will have more thorough answers for you.

Charles Hartman

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to