On Mon, Mar 17, 2008 at 12:01:04PM -0400, Jason Tackaberry wrote:
> On Mon, 2008-03-17 at 16:47 +0100, Duncan Webb wrote:
> > Thanks both Jason and James, it makes sense that the list is created 
> > when the method is first parsed, this is something that I need to watch 
> > out for. I guess that this is only a problem for mutable objects, so 
> > strings and numbers are not a problem.
> 
> They are also evaluated prior to instantiation, but yes, because they
> are immutable it's not a problem in practice.

A different issue of the same 'shooting your foot in python' kind:

array = [[0] * 4] * 3

This creates and initializes a bidimensional array:
[[0, 0, 0, 0],
 [0, 0, 0, 0],
 [0, 0, 0, 0]]

Now after setting array[1][2] = 1 the array contents are:
[[0, 0, 1, 0],
 [0, 0, 1, 0],
 [0, 0, 1, 0]]

This is because all rows point to the same one-dimensional array object -
though, for some reason, all cells in that object do not point to the
same integer.

Not a big deal, but it did trip me up the first time (and, I still don't know
of a good way to create the two-dimensional array with actual separate
copies for each row)

-- 
Michel Lespinasse

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Freevo-devel mailing list
Freevo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freevo-devel

Reply via email to