problems creating and adding class instances to a list:

Xavier Ho contact at xavierho.com
Mon Apr 19 23:29:34 CEST 2010


On Tue, Apr 20, 2010 at 7:21 AM, Robert Somerville <
rsomerville at sjgeophysics.com> wrote:

> class ctest():
>   x = int
>   y = [1,2,3]
>

Variables defined directly under the class are known as "static variables"
in many other languages. Here in Python it's called a class variable, but
they're still the same concept.

What you want is "instance variables", which are not shared by the class
instances, but different depending on each instance instead. That said,

class ctest():
    def __init__(self):
        self.x = int
        self.y = [1, 2, 3]

is probably what you're after.

Cheers,
Xav
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100420/aa14283c/attachment.html>


More information about the Python-list mailing list