append to non-existing list

Yves Glodt y.glodt at sitasoftware.lu
Wed Nov 9 07:46:52 EST 2005


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...?!?

My question is: Is there no way to append to a non existing list?

I am lazy for declaring it first, IMHO it bloats the code, and (don't 
know if it's good to say that here) where I come from (php) I was used 
to not-needing it...


regards,
Yves



More information about the Python-list mailing list