![](https://secure.gravatar.com/avatar/83216248468cc943f59f335b4abfa89c.jpg?s=120&d=mm&r=g)
On 1 Feb 2004, Tobias Herp <- Nummer-5@gmx.net wrote:
Sind atof und das string-Modul nicht deprecated?
Ja, nein.
input=open('file','r') S=input.readlines() res = [] for i in S: res.append([ int(a) for a in i.split(',') ])
(nicht getestet)
Das kann auch nicht funktionieren, da die Koordinaten auch Gleitkommazahlen sein können. Es gibt sicherlich mehrere alternative Möglichkeiten. Was man nimmt, hängt wohl sehr von der genauen Aufgabenstellung ab. def ret_coord (stream): return [eval(num) for line in stream.readlines() for num in line.split(',')] def ret_coord (stream): return [(lambda n: (n.find('.') > -1) and float(n) or int(n))(num) for line in stream.readlines() for num in line.split(',')] def ret_coord (stream): res = [] for line in stream: res.extend(map(lambda n: (n.find('.') > -1) and float(n) or int(n), line.split(','))) return res Obiges sind alles mehr oder minder äquivalente Lösungen (wenn man weiß, daß nur Koordinaten vorkommen, ist »eval« eine gute Alternative). def ret_coord (stream): for line in stream: yield map(lambda n: (n.find('.') > -1) and float(n) or int(n), line.split(',')) Als Generator gefällt es mir fast am besten. Man kann sich dann noch entscheiden, ob man die Koordinaten nicht gleich als Tupel zurückgibt. Karl -- Increasingly, people seem to misinterpret complexity as sophistication, which is baffling -- the incomprehensible should cause suspicion rather than admiration. Possibly this trend results from a mistaken belief that using a somewhat mysterious device confers an aura of power on the user. -- Niklaus Wirth _______________________________________________ Python-de maillist - Python-de@python.net http://python.net/mailman/listinfo/python-de