Seite 1 von 1

Verfasst: Dienstag 8. Februar 2005, 09:28
von Gast
sorry des doppelpostings...

ref_file wurde vorher schon belegt mit "ref_file.txt"

Verfasst: Dienstag 8. Februar 2005, 13:33
von BlackJack
Ich weiss jetzt nicht ob das nicht ein kleines 'u' sein muss.

Ansonsten sag doch bitte mal, was genau nicht funktioniert. Was erwartest Du und was bekommst Du statt dessen.

Verfasst: Dienstag 8. Februar 2005, 13:57
von Dookie
Hi,

"U" muss schon gross sein, siehe pydoc file
geht das?

Code: Alles auswählen

ref_file = file(ref_file, "rU") # rU -> read with "universal newline"
lines_in_ref_file = list(ref_file) #  more efficient than ref_file.readlines()
ref_file.close() 
# remove all newlines
lines_in_ref_file = [x.rstrip('\n') for x in lines_in_ref_file]
könnte man so noch etwas komprimieren:

Code: Alles auswählen

ref_file = file(ref_file, "rU") # rU -> read with "universal newline"
lines_in_ref_file = [x.rstrip('\n') for x in ref_file]
ref_file.close() 
Gruß

Dookie