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
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
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
[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
[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:
[]
-
[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
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
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
Guess i shouldn't think of the __init__(self) function as a constructor
then.
Thanks.
/H
--
http://mail.python.org/mailman/listinfo/python-list
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
10 matches
Mail list logo