[Tutor] printing statement

bob bgailer at alum.rpi.edu
Thu Nov 3 22:54:24 CET 2005

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 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. 

More information about the Tutor mailing list