Max M wrote:
> Yves Glodt wrote:
>> bruno at modulix wrote:
>>
>>> Yves Glodt wrote:
>>>
>>>> Hello,
>>>>
>>>> if I do this:
>>>>
>>>> for row in sqlsth:
>>>> ________pkcolumns.append(row[0].strip())
>>>> ________etc
>>>>
>>>>
>>>> without a prior:
>>>>
>>>> pkcolumns = [];
>>>>
>>>>
>>>> I get this error on first iteration:
>>>> UnboundLocalError: local variable 'pkcolums' referenced before
>>>> assignment
>>>>
>>>>
>>>> I guess that's normal as it's the way python works...?!?
>
>
> Well you could do something like this. (Untested and unrecommended)
>
> self.__dict__.setdefault('pkcolumns', []).append(row[0].strip())
>
> Personally I find
>
> pkcolumns = []
> pkcolumns .append(row[0].strip())
>
> to be nicer ;-)
Yes me too, I'm gonna stick to that... :-)
--
http://mail.python.org/mailman/listinfo/python-list