Accessing class variables

Peter Sommerfeld peter.sommerfeld at gmx.de
Fri Oct 29 19:23:39 EDT 1999


Sorry folks, I'm confused. What's that ?

Python 1.5.2c1 (#56, Apr 12 1999, 14:19:52)  [CW PPC w/GUSI w/MSL]
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>>
>>> class Foo:
...     x = "a class var"
...     def __init__(self,s):
...         self.s = s
...
>>> foo = Foo("an instance var")
>>>
>>> print type(Foo)
<type 'class'>
>>>
>>> print Foo.x
a class var
>>>
>>> print type(foo)
<type 'instance'>
>>>
>>> print foo.s
an instance var
>>>
>>> print foo.x	# huh ?
a class var
>>>

I can access class variables via the instance ?
Bug, new feature or even an old one and I'm crazy ?

-- Peter






More information about the Python-list mailing list