Python Print help ...
Andrew Gould
andrewlylegould at gmail.com
Thu Oct 7 16:19:50 PDT 2010
On Thu, Oct 7, 2010 at 5:00 PM, Ben Duncan <bend at linux4ms.net> wrote:
> I am writing some python programs to do various reporting.
> Is there better ways to do headers and details line then something
> like:
>
> print "ID NO NAME ADDRESS ....." (and so on)
>
> I would like to have string in simply PUT in the line string where I wanted
> it to go:
>
> ie: (Psudeo Code)
>
> string.copy(PRINT_HEADING(1), "ID NO")
> string.copy(PRINT_HEADING(13), "NAME")
>
> Thanks ...
>
> --
> Ben Duncan - Business Network Solutions, Inc. 336 Elton Road Jackson MS,
> 39212
You can find a way to do anything; but if you have to count the spaces
for each program, I don't think it's going to save you a lot of time.
If, however, the lengths of the fields are standard across reports (eg
the "Name" field is always 7 characters long), you may get good use
out of a dictionary. (I have indented code and output with 5 spaces
below).
hdr = {'id':'ID No ', 'name':'Name ','address':'Address '}
print hdr['id] + hdr[name'] + hdr['address']
would result in:
'ID No Name Address '
print hdr['id] + hdr[address'] + hdr['name']
would result in:
'ID No Address Name '
FYI: The print statement is replaced by the print() function in Python 3:
http://docs.python.org/release/3.0.1/whatsnew/3.0.html
Regards,
Andrew
More information about the Linux-users
mailing list