OOP in Python

Romain Guy romain.guy at jext.org
Wed Jun 20 14:47:07 EDT 2001


"static" variables (or class attributes) are defined like this:

class MyClass:
    myStaticVar = 1
    myStaticList = [1, 2, 3]

    # ...

Instance attributes are define like this:

class MyClass:
    #...
    def __init__(self):
        self.myInstanceAttrInt = 2
        self.myInstanceAttrList = [2, 3, 4]

--
Romain "Java Swinguer !" Guy
romain.guy at jext.org
www.jext.org

"Now, don't you worry. The saucers are up there. The graveyard is out there.
But I'll be locked up safely in there."
- Paula Trent, Plan 9 From Outer Space
"Jonas Bengtsson" <jonas.b at home.se> a écrit dans le message news:
4e2ddb70.0106200954.11faa218 at posting.google.com...
> Ok I admit - I am a Python-newbie!
>
> What about local variables and class variables when dealing with
> classes?
> With local vars I mean temporaryly used variables in a function. Will
> they be treated as 'normal' instance attributes? Do I have to delete
> them by myself when I'm leaving a function?
> With class vars I mean if many class instances of a class may share a
> variable. In C++ this is accomplished by a static variable. How do I
> do in Python?
>
> Thanks in advance,
> Jonas B





More information about the Python-list mailing list