Thank you  for the fast reply

Am 13.10.2005 um 19:43 schrieb Kent Johnson:


>   if len(filter(re_name.search, line)) > 0:
> could be written
>   if re_name.search(line):

this is not working  because I am parsing a line in a list (i think):

Traceback (most recent call last):
   File "telekom2.py", line 42, in ?
     if re_month.search(line):
TypeError: expected string or buffer


> or even, since the re is just fixed text,
>   if phone[name] in line:

this won't match anything, the number is only a part of a string...

I read the file in with

read_file = csv.reader(open(sys.argv[1], 'r'), delimiter="\t")


The input file is something like this (6 lines)


"Sonstige Leistungen des Konzerns Deutsche Telekom"     "Inkasso"       
"T-Online 
International AG"       "Ohne Anschluss"        "---"   "---"   "T-Online dsl 
flat max   
       Monatliche Grundgebühr"  "19112" "---"   "25,8100"       "25,81" "16"

"Monatliche Beträge vom 01.09.2005 bis 30.09.2005"      "ISDN"  "Deutsche 
Telekom AG"     "Rufnummer"     "1234561"       "---"   "T-ISDN xxl sunday 
(monatlicherGrundpreis)"        "19487" "---"   "26,9600"       "26,96" "16"

"Monatliche Beträge vom 01.09.2005 bis 30.09.2005"      "T-DSL" "Deutsche 
Telekom AG"     "Rufnummer"     "1234561"       "---"   "Monatlicher Grundpreis 
       
FastPath für T-DSL"     "63215" "---"   "0,8500"        "0,85"  "16"

"Verbindungen Deutsche Telekom vom 17.08.2005 bis 
17.08.2005"     "ISDN"  "Deutsche Telekom 
AG"     "Rufnummer"     "012341234561"  "2"     "Verbindungen zum              
Service 0190x"  "03288" "21"    "0,0533"        "1,12"  "16"

"Verbindungen Deutsche Telekom vom 17.08.2005 bis 
14.09.2005"     "ISDN"  "Deutsche Telekom 
AG"     "Rufnummer"     "012341234561"  "23"    "Verbindungen zu T-Mobile      
AktivPlus xxl sunday"   "19483" "190"   "0,1719"        "32,66" "16"

"Verbindungen Deutsche Telekom vom 17.08.2005 bis 
14.09.2005"     "ISDN"  "Deutsche Telekom 
AG"     "Rufnummer"     "012341234561"  "2"     "Deutschlandverb. AktivPlus 
xxlsunday Mo-Fr Hauptzeit"      "19477" "11"    "0,0396"        "0,44"  "16"

>
>>
>> Is there for example a way to search the whole list and give back all
>> the line numbers containing a string?
>   [ i for i, line in enumerate(rechnung) if "Monatliche" in line ]

hm, it doesn't match:

 >>> import csv
 >>> rechnung=list(csv.reader(open('2005_08_Rechnung.dat', 'r'), 
delimiter="\t"))
 >>> [ i for i, line in enumerate(rechnung) if "Monatliche" in line ]
[]


This matches all lines, not only the ones which have "Moantliche":

 >>> [ i for i, line in enumerate(rechnung) if re_month.search in line ]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 
38, 39, 40]


>
> Kent
>>
>> Regards,
>> Markus
>>
>>
>>
>> phone={ "Markus":"1234561",\
>>      "Eckhard":"1234562",\
>>      "Robert":"1234563",\
>>      "Lei":"1234564"
>>              }
>>
>>
>>
>> for name in phone.keys():    # loop through the list for all names
>>      euro=0 # set at each run to 0
>>      i=0 # Line number
>>
>>      # compile REs
>>      re_name = re.compile(phone[name])
>>      re_month=re.compile("Monatliche")
>>      re_misc=re.compile("Sonstige")
>>      
>>      for line in rechnung:
>>              if len(filter(re_month.search, line)) == 0:     # skip the 
>> monthly
>> costs
>> #            if "Monatliche" in line:
>>                      if len(filter(re_name.search, line)) > 0 and
>> len(filter(re_misc.search, line)) == 0:
>> #                    if phone[name] in line:
>>                              euro += float(rechnung[i][10].replace( ',' , 
>> '.'))
>>                      if len(filter(re_misc.search, line)) > 0:       # misc 
>> services
>>                              if i not in misc_list: # add misc fees only once
>>                                      misc_list.append(i)
>>                                      misc += float(rechnung[i][10].replace( 
>> ',' , '.'))
>>              elif len(filter(re_month.search, line)) > 0:
>>                      if i not in monthly_list: # add monthly occuring fees 
>> only once
>>                              monthly_list.append(i)
>>                              monthly += float(rechnung[i][10].replace( ',' , 
>> '.')) # replace
>> commata with dots then add to the sum
>>              i=i+1           
>>      per_user = ( euro + ( monthly + misc )/ divider )*1.16
>>      total += per_user
>>      print name,": ", per_user
>>
>>
>>
>> --
>> If everything seems to be going well,
>> you  obviously don't know what the hell is going on
>>
>> _______________________________________________
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to