[Tutor] Add newline's, wrap, a long string
Alan Gauld
alan.gauld at btinternet.com
Wed Apr 29 18:44:03 CEST 2009
"Sander Sweers" <sander.sweers at gmail.com> wrote
> What you can do is define all the variables upfront. This way you can
> get rid of the else. Below is an example how you can do this with only
> looping once over the fle.
And you can put the variables as keys of a dictionary and avoid
all the if tests:
data = {'CBUILD':None,
'ACCEPT_KEYWORDS: None,
....
}
> for line in fname:
for keyphrase in data:
> if keyphrase in line:
> output = line.split('"')[1]
> data[keyphrase] = textwrap.fill(output, 80)
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list