Title: Dupicate instances of classes in list
Type: Stage:
Components: Windows Versions: Python 2.5
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, ezio.melotti, mbaynham
Priority: normal Keywords:

Created on 2009-05-26 08:54 by mbaynham, last changed 2009-05-26 12:44 by mbaynham. This issue is now closed.

Messages (14)
msg88340 - (view) Author: Matthew (mbaynham) Date: 2009-05-26 08:54
What I intended was...
I create a list of DIFFERENT instances of the same class, I wanted them
to be different instances, with different values for the properties,
stressing the word "DIFFERENT".

What I originally did was...
The __init__ assigns default values for the properties (eg, iId = 0, and
sName = ''), then I would change to properties before adding it to the
list.  However, the list will contain the right number of elements, but
every element is the same instance of the class.

I resolved this by...
If I change __init__ such that I'm passing it parameters with values to
assign to the properties.  And then adding the instances of the class to
the list.  Then each element in the list is a different instance.  And
this made everything work.
msg88342 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2009-05-26 08:58
Can you please show the code you tried initially?
I suspect that it always adds the same instance to the list...
msg88344 - (view) Author: Matthew (mbaynham) Date: 2009-05-26 09:11
I didn't keep a copy of the code that didn't work.  Sorry.

When I changed the way I was initialising the classes, before adding
them to the list, I didn't change any of the logical flow in my code,
and it started to work.

I know it sounds very strange, like it really shouldn't happen, but it did.
msg88345 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2009-05-26 09:22
OK, then I'll close this issue.

This is probably a typo in your code, like this one that I make from
time to time:
    obj = Obj()
    Obj.sName = 'someName'
msg88348 - (view) Author: Matthew (mbaynham) Date: 2009-05-26 09:48
Trust me this was no typo.

I debugged my code by adding print statements to see what values were
going into the list, and print statements to see the values that were
coming out.

It might be that running code from the application Blender does bazaar
things, or it could be anything, I don't know.  All I know is all the
instances I had in the list, had the same property values as the last
element that was added to the list.  I know it's amazingly weird.
msg88350 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2009-05-26 10:23
Even if it's a real bug, without the code we can't do anything.
Try to reproduce what you did or get that code back somehow (ctrl+z? ;)
msg88352 - (view) Author: Matthew (mbaynham) Date: 2009-05-26 11:30
First File....

This is the main one, it's the one that is called from the Blender
msg88353 - (view) Author: Matthew (mbaynham) Date: 2009-05-26 11:31
Second file....

The loads of code for building a wall
msg88354 - (view) Author: Matthew (mbaynham) Date: 2009-05-26 11:32
Third file...

all the classes for holding the data
msg88355 - (view) Author: Matthew (mbaynham) Date: 2009-05-26 11:33
Forth and final file...

Just a little error handling and stuff I want all my classes to inherit
msg88356 - (view) Author: Matthew (mbaynham) Date: 2009-05-26 11:40
If you want to run it I'm afraid you'll have to:
1) install Blender (
2) put all those files in C:\Program Files\Blender
3) in the Blender application goto scripts ---> Objects ---> Build Walls

Then look at the terminal window that comes with Blender and you'll see
it's just gone wrong.

And if you change the Class ClsFeatureVariables, so that the properties
are set when it initialises you'll see it all works OK.
msg88357 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2009-05-26 11:43
It's a typo :-)
In, line 146:
                    cTempVariable = ClsFeatureVariable
You forgot the () at the end...
msg88358 - (view) Author: Matthew (mbaynham) Date: 2009-05-26 12:00
So why is it able to create instances and add them to the
lstFeatureVariables list, surely it should go wrong there and not allow
the instances to be created.
msg88359 - (view) Author: Matthew (mbaynham) Date: 2009-05-26 12:01
OK, sorry for the rambling, just ignore it....

Date User Action Args
2009-05-26 12:44:40mbaynhamsetfiles: -
2009-05-26 12:44:35mbaynhamsetfiles: -
2009-05-26 12:44:30mbaynhamsetfiles: -
2009-05-26 12:44:25mbaynhamsetfiles: -
2009-05-26 12:14:30amaury.forgeotdarcsetstatus: open -> closed
2009-05-26 12:01:37mbaynhamsetmessages: + msg88359
2009-05-26 12:00:49mbaynhamsetmessages: + msg88358
2009-05-26 11:43:16amaury.forgeotdarcsetmessages: + msg88357
2009-05-26 11:40:10mbaynhamsetmessages: + msg88356
2009-05-26 11:33:47mbaynhamsetfiles: +

messages: + msg88355
2009-05-26 11:32:20mbaynhamsetfiles: +

messages: + msg88354
2009-05-26 11:31:42mbaynhamsetfiles: +

messages: + msg88353
2009-05-26 11:30:56mbaynhamsetfiles: +

messages: + msg88352
2009-05-26 10:23:10ezio.melottisetnosy: + ezio.melotti
messages: + msg88350
2009-05-26 09:48:21mbaynhamsetstatus: closed -> open

messages: + msg88348
2009-05-26 09:22:39amaury.forgeotdarcsetstatus: open -> closed
resolution: not a bug
messages: + msg88345
2009-05-26 09:11:47mbaynhamsetmessages: + msg88344
2009-05-26 08:58:40amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg88342
2009-05-26 08:54:02mbaynhamcreate