global variables
Larry Bates
lbates at syscononline.com
Wed Feb 2 19:26:35 EST 2005
One way to to this is by using keyword args:
class a:
def __init__(self, arg1, arg2, **kwargs):
#
# Dictionary kwargs will have keyword, value pairs
# that can be used as global space.
#
self.arg1=arg1
self.arg2=arg2
self.__dict__.update(kwargs)
return
class b:
def __init__(self, arg1, arg2, **kwargs):
#
# Dictionary kwargs will have keyword, value pairs
# that can be used as global space.
#
self.__dict__.update(kwargs)
self.a=a(arg1, arg2, **kwargs)
return
class c:
def __init__(self, arg1, arg2, **kwargs):
#
# Dictionary kwargs will have keyword, value pairs
# that can be used as global space.
#
self.__dict__.update(kwargs)
self.b=b(arg1, arg2, **kwargs)
return
globals={'global1':1, 'global2':2, 'global3':3, 'global4':4}
C=c(1, 2, **globals)
you will have global1, global2, global3, and global4 attributs
in all classes. If you don't want the attributes, just access
to the values, delete the self.__dict__.update(kwargs) lines.
Larry Bates
alex wrote:
> Hi,
>
> is it possible to create 'global' variables that can be seen in all
> other classes?
>
> Alex
>
More information about the Python-list
mailing list