can python do this?

gangli at msn.com gangli at msn.com
Tue Jun 13 10:43:41 EDT 2000


In article <3945e37b$0$489$7f31c96c at news01.syd.optusnet.com.au>,
  "Jason" <it at onestopent.com.au> wrote:
> $Revisions: ['05/05/2000 06']
> Traceback (innermost last):
>   File "C:\PROGRA~1\PYTHON\TOOLS\IDLE\ScriptBinding.py", line 131, in
> run_module_event
>     execfile(filename, mod.__dict__)
>   File "C:\WINDOWS\Desktop\aeros1.py", line 6, in ?
>     print pair[0] +": "+ `string.split(string.strip(pair[1]),",")`
> IndexError: list index out of range
>
>

This is most like the next line read from text file does not follow the
pattern: tag."one" "two" ....

you may use following modified script:

import string
file = open ("file")
lines = file.readlines()
for line in lines:
    pair = string.split(line,":")
    if len(pair) == 2:
        print pair[0] +": "+ `string.split(string.strip(pair[1]),",")`
    else:
        print 'warning wrong format line %s'%pair
file.close()



Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list