OOP in Python

Scherer, Bill Bill.Scherer at VerizonWireless.com
Wed Jun 20 14:14:50 EDT 2001


On 20 Jun 2001, Jonas Bengtsson wrote:

> 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?

No, reference counting or garbage collection will take care of these for
you.

> 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?

class spam:
  classVariable1 = "howdy y'all"
  classVariable2 = 22.7
  def __init__(self):
    self.instanceVariable1 = time.time()


All instances of spam will have the same (classVariable1, classvariable2).
Each instance of spam will (generally) have a unique value for
instanceVariable1.


>
> Thanks in advance,
> Jonas B
>

William K. Scherer
Sr. Member of Applications Staff - Verizon Wireless
Bill.Scherer_at_VerizonWireless.com





More information about the Python-list mailing list