adjust

Michael Hoffman cam.ac.uk at mh391.invalid
Tue Apr 24 07:10:44 EDT 2007


saif.shakeel at gmail.com wrote:
>      How do i right adjust my output using python.

http://docs.python.org/lib/typesseq-strings.html

> minlength=   3,   3,   4,   2,  10,  10,  40,   2, 150,   4,   1,
> 2,   2,   1,   2,   1,   6,   3,  17,   1,

Something like:

 >>> def write_sequence(label, sequence):
...     expanded_text = ",".join("%4d" % item for item in sequence)
...     print "%s=%s" % (label, expanded_text)
...
 >>> write_sequence("minlength", minlength)
minlength=   3,   3,   4,   2,  10,  10,  40,   2, 150,   4,   1

Completing with a trailing ",", using the entire sequence instead of a 
subset, and dealing with your hex constants are left as an exercise to 
the reader.
-- 
Michael Hoffman



More information about the Python-list mailing list