M
Markus Rosenstihl
Hi,
I wonder if i can make this nicer:
In my case a list is created from a bill which is a tab seperated file
and each line looks like this:
"Verbindungen Deutsche Telekom vom 03.08.2005 bis
10.08.2005" "ISDN" "Deutsche Telekom
AG" "Rufnummer" "123456789" "3" "Verbindungen zu T-Mobile
AktivPlus xxl sunday" "19483" "19" "0,1719" "3,27" "16"
I create the list in the following way:
rechnung_raw=open('filename', 'r').readlines()
for line in rechnung_raw:
the_line=string.split(line, '\t')
rechnung.append(the_line)
Now, I have a loop which does basically:
for element in anotherlist: #anotherlist contains line numbers
euro=euro + float(string.replace(string.strip(rechnung[element][10],
'"'), ',' , '.'))
I replace commata with dots, then delete leading/trailing "s then add
to a sum after converting it to a float.
This looks ugly (I htink) and I wonder if there is a nicer way to
strip commata and change the comma to a dot already when reading in.
Or should i do it with a shell script before processing in python?
Regards
Markus
I wonder if i can make this nicer:
In my case a list is created from a bill which is a tab seperated file
and each line looks like this:
"Verbindungen Deutsche Telekom vom 03.08.2005 bis
10.08.2005" "ISDN" "Deutsche Telekom
AG" "Rufnummer" "123456789" "3" "Verbindungen zu T-Mobile
AktivPlus xxl sunday" "19483" "19" "0,1719" "3,27" "16"
I create the list in the following way:
rechnung_raw=open('filename', 'r').readlines()
for line in rechnung_raw:
the_line=string.split(line, '\t')
rechnung.append(the_line)
Now, I have a loop which does basically:
for element in anotherlist: #anotherlist contains line numbers
euro=euro + float(string.replace(string.strip(rechnung[element][10],
'"'), ',' , '.'))
I replace commata with dots, then delete leading/trailing "s then add
to a sum after converting it to a float.
This looks ugly (I htink) and I wonder if there is a nicer way to
strip commata and change the comma to a dot already when reading in.
Or should i do it with a shell script before processing in python?
Regards
Markus