append to non-existing list

Fredrik Lundh fredrik at pythonware.com
Wed Nov 9 14:05:36 CET 2005


Yves Glodt wrote:

> 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...?!?
>
> My question is: Is there no way to append to a non existing list?

how do you expect Python to figure out what kind of empty object
you want ?

</F>






More information about the Python-list mailing list