ich versuche fertige Methoden eines in Python und C programmieren Simulationsmodells einzubinden. Eine der Funktionen (mit dem im folgenden beschriebenen Fehler) liest zeilenweise Werte (Koordinaten x,y) aus einer Datei aus und speichert diese dann als Punkte (float) ab.
Methode:
Code: Alles auswählen
def readUngenerateFile(fd):
"""
import a file, ofile, with the format
[poly]
poly format:
First line: <# of polynomial> <x centroid> <y centroid>
Following lines: <x> <y>
last line: "END"
"""
END_DELIMITER = 'END'
points = []
segments = []
isEnd = False
line = fd.readline() #not used <# of polynomial> <x> <y>
while not isEnd:
line = fd.readline()
fragments = line.split()
vert = [float(fragments.pop(0)),float(fragments.pop(0))]
points.append(vert)
PreviousVertIndex = len(points)-1
firstVertIndex = PreviousVertIndex
line = fd.readline() #Read the next line
while not line.startswith(END_DELIMITER):
#print "line >" + line + "<"
fragments = line.split()
vert = [float(fragments.pop(0)),float(fragments.pop(0))]
points.append(vert)
thisVertIndex = len(points)-1
segment = [PreviousVertIndex,thisVertIndex]
segments.append(segment)
PreviousVertIndex = thisVertIndex
line = fd.readline() #Read the next line
i =+ 1
# If the last and first segments are the same,
# Remove the last segment and the last vertex
# then add a segment from the second last vert to the 1st vert
thisVertIndex = len(points)-1
firstVert = points[firstVertIndex]
thisVert = points[thisVertIndex]
#print "firstVert",firstVert
#print "thisVert",thisVert
if (firstVert[0] == thisVert[0] and firstVert[1] == thisVert[1]):
points.pop()
segments.pop()
thisVertIndex = len(points)-1
segments.append([thisVertIndex, firstVertIndex])
line = fd.readline() # read <# of polynomial> <x> <y> OR END
#print "line >>" + line + "<<"
if line.startswith(END_DELIMITER):
isEnd = True
#print "points", points
#print "segments", segments
ungenerated_dict = {}
ungenerated_dict['points'] = points
ungenerated_dict['segments'] = segments
return ungenerated_dict
Bei Zeile0
650627.026,9894796.636
650616.492,9894795.720
650608.560,9894795.031
...
...
END
Code: Alles auswählen
vert = [float(fragments.pop(0)),float(fragments.pop(0))]
Ich habe leider noch keine Ahnung von Python, leider aber auch nicht die Zeit, mich länger damit auseinander zu setzen. Sie jemand von euch, wo der Fehler liegt bzw. wie das Dateiformat aussehen müsste?ValueError: invalid literal for float(): 650627.026,9894796.636
Beste Grüße,
Arne