Combining Lists and Tupels
Steven Taschuk
staschuk at telusplanet.net
Thu May 22 10:22:46 EDT 2003
Quoth Martin P:
[...]
> f=open("test.csv")
> try:
> while 1:
> currentline=f.readline()
> data=string.split(currentline, ";")
>
> address=data[2], data[3], data[4]
> list[i]=data[0], data[1], address
> i+=1
> finally:
> print "test error"
>
> But this does not work. [...]
*What* doesn't work? Tell us what you expect this code to do, and
what it does instead. Don't make us guess; there's several
strange things in this code.
> [...] I think my problem is with the combination of the
> list[i] and the Tupel address.
Why do you think this? Again, don't make us guess.
Now I'll guess. I guess that you're seeing an exception raised at
the line
list[i]=data[0], data[1], address
One obvious problem here is that you nowhere create an object by
the name 'list'; so instead this name will refer to the built-in
list type, which cannot be subscripted. If this happens to be
your problem, then adding
mylist = []
up top (before the loop) and changing that line to
mylist[i] = data[0], data[1], address
will fix *that* problem. Then you'll encounter another problem on
the same line.
--
Steven Taschuk staschuk at telusplanet.net
"I'm always serious, never more so than when I'm being flippant."
-- _Look to Windward_, Iain M. Banks
More information about the Python-list
mailing list