Roman Suzi <[EMAIL PROTECTED]> writes: > On Thu, 3 Nov 2005, Chris McCoy wrote: >>> gridSystemId = [[None]*columns]*rows >> You've made gridSystemID a list of `rows` references to the SAME "inner" >> list, so the behavior you observe is the only possible one. >> If you want copies instead, ASK for copies...: >> gridSystemId = [ [None]*columns for x in xrange(rows) ] > Interesting, could not pychecker recognize such situations in Python > code and give warnings?
Well, it could always just issue warnings everytime it saw a list multiplied by something. But that would get annoying in the cases where that idiom doesn't have problems - which is naturally most such usages. Your example included one such, which is why the translation wasn't to: gridSystemId = [[None for y in xrange(columns)] for x in xrange(rows)] WRONG [None] * columns doesn't have problems. Nor does any other immutable object. So to avoid spurious warnings, pychecker would have to know whether the objects in the list were immutable or not. It could guess that if the objects are builtin types, but not for other types. <mike -- Mike Meyer <[EMAIL PROTECTED]> http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list