First of all, my excuses, this may be a bit more related to Python
programming rather than specific web2py programming. But I have bumped
into something that has made me loose a lot of time, and thought I'd
share it, and maybe make a fool of myself:

If I append values after asigning them as pv[index] previously I get
the undesired result of val as if it had stored a list of pointers to
a variable.
In [33]: val = []
In [34]: pv = [0,0]
In [35]: for i in range(1,5):
   ....:     pv[0]=i
   ....:     val.append(pv)
   ....:
In [36]: val
Out[36]: [[4, 0], [4, 0], [4, 0], [4, 0]]

I need to do this to make it work: append(pv[:])
In [37]: val = []
In [38]: for i in range(1,5):
    pv[0]=i
    val.append(pv[:])
   ....:
In [41]: val
Out[41]: [[1, 0], [2, 0], [3, 0], [4, 0]]

Doing this, everything is also correct:
In [47]: for i in range(1,5):
    pv= [i,0]
    val.append(pv)
   ....:
In [50]: val
Out[50]: [[1, 0], [2, 0], [3, 0], [4, 0]]

This is probably documented or a basic programming concept that I am
completelly missing, although I have not been able to find a reference
to the matter.
-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.


Reply via email to