[Tutor] interesting behaviour with postional output
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
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, element_list))
> I get nice, lined up columns on the screen. When I write to a file like
> new_line = ('%-40s%s%s' % (element_list, element_list,'\n'))
> 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