python - List elements to variables -
inspired accepted answer reading utf8 csv file python, i've tried following get
valueerror: need more 5 values unpack
seems empty strings tripping me here. there function should apply row
make work? i'll need work these variables individually further down line. thanks.
def encodevar(x): return x row = ['85123', '', '123 address', '', '', 'tucson', 'az ', 'the company name', '', ''] zip5,zip4,strname,strnumber,strsuite,city,state,busname,lname,fname in row: hhid = encodevar( zip5 ) +\ encodevar( zip4 ) +\ encodevar( stname ) +\ encodevar( stnumber ) +\ encodevar( stsuite ) +\ encodevar( busname )
you looping over row
, means each element iterated on separately.
just assign directly variables:
zip5, zip4, strname, strnumber, strsuite, city, state, busname, lname, fname = row
because looping on individual values, trying unpack zip5
value 10 names:
zip5, zip4, strname, strnumber, strsuite, city, state, busname, lname, fname = '85123'
python treats string value, '85123'
sequence of 5 characters, finding 5 don't fit 10 names, throwing exception saw.
Comments
Post a Comment