Re: Two classes problem

2005-02-03 Thread Caleb Hattingh
Gurpreet You can manage the namespace more formally. Or to put it another way, "global" gives me the heebie-jeebies. I recently worked on a project replacing a legacy reactor model in FORTRAN, and between COMMON blocks, and GOTO statements, I didn't know up from down. How about this: *** cl

Re: Two classes problem

2005-02-02 Thread Steven Bethard
Gurpreet Sachdeva wrote: The purpose is, I pass a list to a class in a module but I want to use that list out of the scope of that class and that too not in any other class or a function but in the main program... The problem is that when I import that, the statements in the module which are not in

Re: Two classes problem

2005-02-02 Thread Gurpreet Sachdeva
The purpose is, I pass a list to a class in a module but I want to use that list out of the scope of that class and that too not in any other class or a function but in the main program... The problem is that when I import that, the statements in the module which are not in the class are executed f

Re: Two classes problem

2005-02-02 Thread Caleb Hattingh
Steven, thanks for your help once again :) so you could write the code like: test = 'first' class aclass: def __init__(self, value): mod = __import__(__name__) mod.test = value This is sweet. I really like this technique for manipulating module-scope identifiers (from with

Re: Two classes problem

2005-02-02 Thread Steven Bethard
Caleb Hattingh wrote: ===file: a.py=== # module a.py test = 'first' class aclass: def __init__(self, mod, value): mod.test = value# Is there another way to refer to the module this class sits in? ===end: a.py=== You can usually import the current module with: __import_

Re: Two classes problem

2005-02-02 Thread Caleb Hattingh
Hi It would help if you could describe the purpose you have in mind for doing this. There is a cute way of doing what you want: ===file: a.py=== # module a.py test = 'first' class aclass: def __init__(self, mod, value): mod.test = value# Is there another way to refe

Re: Two classes problem

2005-02-02 Thread [EMAIL PROTECTED]
If you create a.py like -test = 'Spam' - -class a: -def __init__(self, arg): -global test -test = arg -self.result = arg + ' added' -def __call__(self): -return self.result and b.py like -import a -a.test = 'donkey' -x = a.a('dinosaur') -print a.test It will