[Tutor] Add newline's, wrap, a long string

Sander Sweers sander.sweers at gmail.com
Wed Apr 29 15:28:16 CEST 2009


2009/4/29 David <david at abbottdavid.com>:
> Here is the whole program so far, what it does is it logs into a druple web
> site and posts. I would like to make it better, as you can see I do the same
> thing over and over.
>
> http://linuxcrazy.pastebin.com/m7689c088

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.

CBUILD = ''
ACCEPT_KEYWORDS = ''

for line in fname:
    if 'ACCEPT_KEYWORDS' in line:
        output = line.split('"')[1]
        ACCEPT_KEYWORDS = textwrap.fill(output, 80)

    if 'CBUILD' in line:
        output = line.split('"')[1]
        CBUILD = textwrap.fill(output, 80)

etc etc

Greets
Sander


More information about the Tutor mailing list