ich habe folgendes Problem: ich will Zahlenspalten, welche sich am Ende eines Textfiles befinden auslesen, und in eine Liste umwandeln. Hier ist mal folgende Beispieldatei:
Als Lösungsansatz habe ich auf empfehlung meines Pythonbuches das Structmodul verwendet. Mit folgendem Programmcode:PATH PLOT
lcase1
Inc : 49
Time : 9.800000e-01
Pres : 0.000000e+00
Curve 1
X : Arc Length
Y : Equivalent Von Mises Stress Layer 1
Node X Y
----------------------------------------
87 0.000000e+00 7.430990e+02
12 1.851562e+00 5.764913e+02
13 3.726562e+00 9.063725e+02
14 5.671875e+00 1.055981e+03
Code: Alles auswählen
#!/usr/bin/env python
import struct
recordFormat='hdd'
recordSize=struct.calcsize(recordFormat)
resultList=[]
count=12
f=open("/home/tfr002/test/vm.txt", "rb")
while f.readline() is not "":
count=count+1
record=f.read(recordSize)
resultList.append(struct.unpack(recordFormat, record))
if record=='':
f.close()
break
print resultList
kann mir jemand einen Tip geben?....
resultList.append(struct.unpack(recordFormat, record))
struct.error: unpack str size does not match format