[Tutor] interesting behaviour with postional output

Chris Fuller cfuller084 at thinkingplanet.net
Mon Nov 14 20:26:00 CET 2011

Fonts can be categorized as "fixed" or "proportional" widths.  Proportional 
width fonts have different widths depending on the character.

If you want to line up text, you must use fixed width fonts like courier, or 
use tabs, but that can be unreliable.  You can get fancy and measure the width 
of a string in some font (if you have an API that allows it), but that is 
rarely worthwhile.


On Monday 14 November 2011, Cranky Frankie wrote:
> I'm working on writing out postional output. When I use this statement:
> print('%-40s%s' % (element_list[0], element_list[1]))
> I get nice, lined up columns on the screen. When I write to a file like
> this:
> new_line = ('%-40s%s%s' % (element_list[0], element_list[1],'\n'))
> file_out.write(new_line)
> a very funny thing happens. When I open the file in Notepad, the
> columns are not lined up, however when I switch the font to Courier,
> they * are* lined up. So what's happening is the output statement is
> working correctly - the second column starts in the 41st postion - but
> you have to use a non-proportional font to see it.
> I was hoping to not have the font be an issue.
> Very interesting.

More information about the Tutor mailing list