Declaration of an array of unspecified size

Max M maxm at mxm.dk
Mon Sep 1 02:47:40 EDT 2003


Bertel Lund Hansen wrote:

> Ulrich Petri skrev:

>>>class PopMailServer:
>>>  host = ""
>>>  user = ""
>>>  password = "*"
>>>  mails = 0
>>>  mail[] # This is wrong but what do I do?
>>
>>mail = [] #would work
> 
>>But you are creating class-variables here. Are you sure thats what you want?
> 
> Yes. I have the habit from Java and C++. Is there a better way to
> declare them in Python?


Class variables holds the same value for all instances of your object. 
If you want different instances to be able to have different values you 
should declare them as instance variables in the __init__ method.

class PopMailServer:

     def __init__(self):
         self.host = ""
         self.user = ""
         self.password = "*"
         self.mails = 0
         self.mail = []


regards Max M





More information about the Python-list mailing list