[Tutor] long lines in print
Christian Tismer
tismer@appliedbiometrics.com
Fri, 16 Apr 1999 15:28:41 +0200
Arne Mueller wrote:
>
> Hi All,
>
> is there a chance to split a long python 'statements'
> line into several lines?
>
> The following statement is far too long for one emacs
> line and I'd line to split it up so that the statement
> becomes more readable. Is there a way to put the list
> of values (hsp.score, hsp.e, hsp.identity) in the next
> line? I mean, that'd collide with python indentation,
> wouldn't it?
The Python indentation rules do only apply for a new
statement line. If you can manage to continue your statement,
indentation is no problem. Continuation is done by ending
a line with a backslash.
> print 'HSP: score = %f, e = %f, identity = %d\%' % (hsp.score, hsp.e,
> hsp.identity)
print 'HSP: score = %f, e = %f, identity = %d\%' % \
(hsp.score, hsp.e, hsp.identity)
will do it.
Another way is to build your format string dynamically, like
my_fmt = 'HSP: score = %f, e = %f, identity = %d\%'
print my_fmt % (hsp.score, hsp.e, hsp.identity)
This can sometimes make it easier to change the formatting
of output, especially if you need the same formats in different
lines, maybe with slight modifications.
ciao - chris
--
Christian Tismer :^) <mailto:tismer@appliedbiometrics.com>
Applied Biometrics GmbH : Have a break! Take a ride on Python's
Kaiserin-Augusta-Allee 101 : *Starship* http://starship.python.net
10553 Berlin : PGP key -> http://wwwkeys.pgp.net
PGP Fingerprint E182 71C7 1A9D 66E9 9D15 D3CC D4D7 93E2 1FAE F6DF
we're tired of banana software - shipped green, ripens at home