Strange tab problem!

Bob Gailer bgailer at alum.rpi.edu
Mon Aug 25 17:21:49 EDT 2003


At 11:17 PM 8/24/2003 -0400, tjland at iserv.net wrote:

>Okay i wrote a small program that allows users to creat book listings
>featuring copyright date author and title. Now when i display the book
>listings i get this.
>
>Book:  testover6        Author:  ???    Copyright: 2003
>Book:  testu6   Author:  ???    Copyright: 2003
>
>Okay now after the book title their is supposed to a tab the coding goes
>like this.
>
>for x in title_author.keys():
>         print "Book: ",x," \tAuthor: ",title_author[x],"
>\tCopyright:",title_copyright[x]
>
>it seems that whenever i go over six characters it adds another tab. Is
>there a preset field limit to six bytes. What is happening?

Others have told you what's happening. I think the best solution is to use 
% formatting:
"Book:  %12s Author:  %12s Copyright: %4s" % (title, author, copyright)
This will give you a string with the %..s replaced with the corresponding 
value from the tuple, right aligned by 12 and 4.
Example:
"Book:  %12s Author:  %12s Copyright: %4s" % ("Red Fire", "Jones", 2003)
results in
'Book:      Red Fire Author:         Jones Copyright:  2003'

Bob Gailer
bgailer at alum.rpi.edu
303 442 2625
-------------- next part --------------

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003


More information about the Python-list mailing list