Re: Python instances

2005-04-21 Thread Bengt Richter
On Thu, 21 Apr 2005 07:58:14 -0400, Kent Johnson <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: >> The following shows nothing static anywhere, yet a class has been defined, >> an instance created, and >> __init__ called with initial value, and the value retrieved as an attribute >> of the ret

Re: Python instances

2005-04-21 Thread Kent Johnson
Bengt Richter wrote: The following shows nothing static anywhere, yet a class has been defined, an instance created, and __init__ called with initial value, and the value retrieved as an attribute of the returned instance, and it's all an expression. >>> type('C', (), {'__init__': lambda self,v

Re: Python instances

2005-04-21 Thread Bengt Richter
On Wed, 20 Apr 2005 08:33:48 -0400, Kent Johnson <[EMAIL PROTECTED]> wrote: >[EMAIL PROTECTED] wrote: >> Guess i shouldn't think of the __init__(self) function as a constructor >> then. > >No, that's not it. You shouldn't think of variables defined outside of a >method as instance variables. > >I

Re: Python instances

2005-04-20 Thread M.E.Farmer
[EMAIL PROTECTED] wrote: > Hi, > > How do python instances work? > Why does the code at the end of my posting produce this output: > > list in a: > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] > list in b: > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] > > instead of > > list in a: >

Re: Python instances

2005-04-20 Thread EuGeNe
[EMAIL PROTECTED] wrote: Hi, How do python instances work? Why does the code at the end of my posting produce this output: list in a: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] list in b: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] instead of list in a: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] list in b

Re: Python instances

2005-04-20 Thread Kent Johnson
[EMAIL PROTECTED] wrote: Guess i shouldn't think of the __init__(self) function as a constructor then. No, that's not it. You shouldn't think of variables defined outside of a method as instance variables. In Java for example you can write something like public class MyClass { private List lis

Re: Python instances

2005-04-20 Thread Bengt Richter
On 20 Apr 2005 00:44:53 -0700, [EMAIL PROTECTED] wrote: >Guess i shouldn't think of the __init__(self) function as a constructor >then. >Thanks. Depends on what you think when you think "constructor" ;-) Read about both __new__ and __init__. The former is always necessary to create an object, and

Re: Python instances

2005-04-20 Thread Laszlo Zsolt Nagy
Guess i shouldn't think of the __init__(self) function as a constructor then. __init__ is THE constructor in Python -- _ Laszlo Nagy web: http://designasign.biz IT Consultantmail: [EMAIL PROTECTED

Re: Python instances

2005-04-20 Thread henrikpierrou
Guess i shouldn't think of the __init__(self) function as a constructor then. Thanks. /H -- http://mail.python.org/mailman/listinfo/python-list

Re: Python instances

2005-04-20 Thread Roland Heiber
Hi, class MyClass: list = [] you have "list" defined as a classmember, not an instancemember. So "list" ist defined ONCE for all instances. Try this instead: class MyClass: def __init__(self): self.list = [] [...] and use self.list ... HtH, Roland -- http://mail.python.org/mailman

Python instances

2005-04-20 Thread henrikpierrou
Hi, How do python instances work? Why does the code at the end of my posting produce this output: list in a: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] list in b: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] instead of list in a: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] list in b: [] class MyClass