Mail extraction problem (something's wrong with split methods)

Peter Otten __peter__ at web.de
Sat Sep 11 14:29:53 EDT 2004


Luka Milkovic wrote:

> temp = [mail.read()]
> enc_txt = "\n".join(temp)

These two lines an be simplified to

enc_text = mail.read()

> begin = enc_txt.find(", '[")+len(", '[")
> ending = enc_txt.find("]', ")

A guess: you are not checking whether the ending "]', " is really found. It
may well be that it is not and therefore ending set to -1 -- which means
end_txt2 will contain all characters from 'begin' until the end of the
string excluding only the last character.

> enc_txt2 = (enc_txt[begin:ending])
> mail.close()

next two lines are superfluous:

> lines = enc_txt2.splitlines()
> enc_txt3 = ' '.join([line.strip() for line in lines])

> split = re.split(",", enc_txt3)

better IMHO:

split = enc_txt2.split(",")

you need only one of the following lines:

> enc = [int(elem) for elem in split]
> enc = map(int, split)
 
If my guess doesn't pinpoint the problem, I suggest that you post the actual
code and data that reproduces the error.

Peter





More information about the Python-list mailing list