Two classes problem

wittempj at hotmail.com wittempj at hotmail.com
Wed Feb 2 14:12:34 EST 2005


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 print 'dinosaur', so you changed the global variable. The thing
is however that this is a highly confusing way of programming for me,
so I would not use it just because it is possible




More information about the Python-list mailing list