Found it. This is what I was looking for:
"""
>>> print ('file'+'dir'.center(20))+('\n'+'='*15)
file dir
===============
>>>
"""
It's actually a string operator 'center(width)' that I was
looking for.
I saw the '%', but that is wahat I wanted to use.
Johan
Colin J. Williams wrote:
bob
wrote:
At 11:31 AM 11/3/2005, Johan Geldenhuys
wrote:
Hi all,
Just a quick question;
How do I code this output:
"""
files dirs
==========
"""
I want to print something a few space away from the left side or in the
middle of the line.
In the Python Library Reference look up 2.3.6.2 String Formatting
Operations - % interpolation
In general you create a "template" of the desired output with %s (or
other conversion type) wherever you want a value substituted.
"%-15s%-15s" % ('files', 'dirs') will give
"files dirs "
"%-15s%-15s" % (filename, directory) will give
"funny.doc c:\root "
assuming the variabies filename, directory have the values shown.
the - means left align, 15 is field width.
_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
Have you considered the % formatting operator?
See 2.3.6.2 String Formatting Operations in the Library Reference.
Colin W.
|
_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor