Question: How do I format printing in python

Donald 'Paddy' McCarthy paddy3118 at netscape.net
Wed Jun 25 21:39:26 CEST 2008


Lie wrote:
> On Jun 24, 12:12 am, joemacbusin... at yahoo.com wrote:
>> Hi All,
>>
>> How do I format printed data in python?
>> I could not find this in the Python Reference Manual:http://docs.python.org/ref/print.html
>> Nor could I find it in Matloff's great tutorial:http://heather.cs.ucdavis.edu/~matloff/Python/PythonIntro.pdf
>>
>> For example, how do I turn this:
>>
>> 512 Jun 5 2004 X11r6
>> 22 Jan 17 2005 a2p
>> 22 Jan 17 2005 acctcom
>> 5374 Sep 15 2002 acledit
>> 5664 May 13 2004 aclget
>> 12020 May 13 2004 aclput
>> 115734 Jun 2 2004 adb
>> 46518 Jun 4 2004 admin
>> 66750 Sep 16 2002 ali
>> 1453 Sep 15 2002 alias
>> 28150 Jun 4 2004 alog
>> 15 May 12 2005 alstat
>>
>> into this:
>>
>> 512        Jun   5   2004    X11r6
>> 22         Jan   17  2005    a2p
>> 22         Jan   17  2005    acctcom
>> 5374       Sep   15  2002    acledit
>> 5664       May   13  2004    aclget
>> 12020      May   13  2004    aclput
>> 115734     Jun   2   2004    adb
>> 46518      Jun   4   2004    admin
>> 66750      Sep   16  2002    ali
>> 1453       Sep   15  2002    alias
>> 28150      Jun   4   2004    alog
>> 15         May   12  2005    alstat
>>
>> Thank you
> 
> There is string formatting
> 
> print formatspecifier_string % data_sequence
> The format specifier is similar to the one used in C's printf, and
> data sequence may be tuple or list. Dictionary may also be used for
> data, but it has its own way to specify string formatting since
> dictionary is unordered but "indexed" by the dict key.

I have attached a prog I wrote to answer someones elses similar problem.

- Paddy.

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: pprinter2.py
URL: <http://mail.python.org/pipermail/python-list/attachments/20080625/7be1bae3/attachment.ksh>


More information about the Python-list mailing list