Re: [Tutor] Populating a list with object to be called by a class

2012-09-20 Thread Steven D'Aprano
On 21/09/12 03:18, eryksun wrote: On Thu, Sep 20, 2012 at 12:57 PM, eryksun wrote: I forgot the obligatory warning about class variables. The subclass gets a shallow copy of the parent class namespace. The in-place ^^^ >>> Y.data += [1] >>> X.data # modified p

Re: [Tutor] Populating a list with object to be called by a class

2012-09-20 Thread eryksun
On Thu, Sep 20, 2012 at 3:39 PM, Steven D'Aprano wrote: > On 21/09/12 02:57, eryksun wrote: >> >> On Thu, Sep 20, 2012 at 12:25 PM, eryksun wrote: > > Preferred terminology is attribute, not variable. Class attributes live > in the class and are shared across all instances. Instance attributes >

Re: [Tutor] Populating a list with object to be called by a class

2012-09-20 Thread Steven D'Aprano
On 21/09/12 02:57, eryksun wrote: On Thu, Sep 20, 2012 at 12:25 PM, eryksun wrote: cls._count += 1 I forgot the obligatory warning about class variables. Python is not Java. In Python, classes are first-class objects (no pun intended) and can be assigned to variables the same

Re: [Tutor] Populating a list with object to be called by a class

2012-09-20 Thread Peter Otten
Ara Kooser wrote: > Morning, > > I dug out some old code from 5 years ago to clean up and get in working > order. It's a simple agent based model. I have class called Ant which > contains all the ant-like functions. > > I have a list that tracks the ants but I did this is a very crude way. I >

Re: [Tutor] Populating a list with object to be called by a class

2012-09-20 Thread eryksun
On Thu, Sep 20, 2012 at 12:57 PM, eryksun wrote: > > I forgot the obligatory warning about class variables. The subclass > gets a shallow copy of the parent class namespace. The in-place ^^^ > >>> Y.data += [1] > >>> X.data # modified parent, too > [1] > >>> Y.da

Re: [Tutor] Populating a list with object to be called by a class

2012-09-20 Thread eryksun
On Thu, Sep 20, 2012 at 12:25 PM, eryksun wrote: > > cls._count += 1 I forgot the obligatory warning about class variables. The subclass gets a shallow copy of the parent class namespace. The in-place addition above works because numbers are immutable. However, an in-place operation o

Re: [Tutor] Populating a list with object to be called by a class

2012-09-20 Thread eryksun
On Thu, Sep 20, 2012 at 10:41 AM, Ara Kooser wrote: > > I have a list that tracks the ants but I did this is a very crude way. I > basically copied and pasted everything in there like this: > > ants = > [Ant("Red_1","Red","yellow_food"),Ant("Yellow_1","Yellow","red_food"), > Ant("Red_2","Red","yel

Re: [Tutor] Populating a list with object to be called by a class

2012-09-20 Thread Ara Kooser
Oscar, Thanks for that. I feel a bit silly. I forgot about the % which was hanging me up. I am trying to be a better coder. More work ahead for me! ara On Thu, Sep 20, 2012 at 9:01 AM, Oscar Benjamin wrote: > On 20 September 2012 15:41, Ara Kooser wrote: > >> Morning, >> >> I dug out some

Re: [Tutor] Populating a list with object to be called by a class

2012-09-20 Thread Oscar Benjamin
On 20 September 2012 15:41, Ara Kooser wrote: > Morning, > > I dug out some old code from 5 years ago to clean up and get in working > order. It's a simple agent based model. I have class called Ant which > contains all the ant-like functions. > > I have a list that tracks the ants but I did th

Re: [Tutor] Populating a list with object to be called by a class

2012-09-20 Thread Emile van Sebille
On 9/20/2012 7:41 AM Ara Kooser said... Morning, I dug out some old code from 5 years ago to clean up and get in working order. It's a simple agent based model. I have class called Ant which contains all the ant-like functions. I have a list that tracks the ants but I did this is a very crud

[Tutor] Populating a list with object to be called by a class

2012-09-20 Thread Ara Kooser
Morning, I dug out some old code from 5 years ago to clean up and get in working order. It's a simple agent based model. I have class called Ant which contains all the ant-like functions. I have a list that tracks the ants but I did this is a very crude way. I basically copied and pasted everyt