Seite 1 von 1

AttributeError: 'tuple' object has no attribute 'split'

Verfasst: Dienstag 20. Januar 2009, 08:30
von tgooper
Hallo,

ich möchte folgende Input Datei einlesen und dann in einer Liste verarbeiten.

--------------------------
| PersNr|LArt| Betrag|
|------------------------|
| 100|/560| 2.028,58 |
| 100|9374| 8,58 |
| 117|/560| 543,31 |
| 12117|9374| 1.543,31 |
| 118|/560| 2.020,22 |
|25841108|9374| 20,22 |
--------------------------

Code: Alles auswählen

from itertools import izip

mylist = list()
datei = "input01.txt"


with open(datei) as lines:
  for line_a in izip(lines):
	 try:
		  pernr, loa , amt = line_a.split(None,2)
		  mylist.append((pernr, oa, amt,))
	 except ValueError:
	    error = error +1

print mylist[1]
Beim Aufruf des Programmes bekomme ich folgende Fehlermeldung:
Traceback (most recent call last):
File "UeG_vergl_95_v01.py", line 10, in <module>
pernr, loa , amt = line_a.split(None,2)
AttributeError: 'tuple' object has no attribute 'split'

Gibt es außer split noch eine Möglichkeit, dass ich den Inhalt der Zeile line_a in eine Liste speichern kann??

thanx
Tgooper

Verfasst: Dienstag 20. Januar 2009, 08:58
von sma
Was soll das `izip`? Lass es einfach weg.

Stefan