On Sat, 23 Apr 2005, Tom Tucker wrote:

> Good evening!  Does Python have a print function similar to Perl
> format output (example below)?

Hi Tom,

Not exactly, but we can get something close, by using the String
Formatting operators.

    http://www.python.org/doc/current/lib/typesseq-strings.html

The example above might be written as:

######
code = "hi"
date = "0420"
descript = "a test of formatting"
amt = 3.14
balance = 2.71
text = """
%-5s %4s %-19s %5.2f %5.2f
""" % (code, date, descript, amt, balance)
print text
######

If you have more questions, please feel free to bring them to the group.

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to