Two classes problem

Gurpreet Sachdeva gurpreet.sachdeva at gmail.com
Thu Feb 3 00:49:34 EST 2005


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 first and then the variable
gets intiallised...
I will explain with the example...

-global test
-
-class a:
-        def __init__(self,test):
-                global test
-                print test
-
-print 'Outside: '+test

I want to print that variable test which I am giving to the class as
an argument, in the scope of main...
I know it is not a good way of programming but my situation is like this...
But is this possible or not? If I pass test as 'Garry' can I (by any
way) print 'Outside: Garry' with that print statement... (in the main
scope)

Thanks and Regards,
Garry



More information about the Python-list mailing list