[Tutor] Create a table by writing to a text file.
Mark Lawrence
breamoreboy at yahoo.co.uk
Wed Feb 22 15:03:28 CET 2012
On 22/02/2012 13:40, Evert Rol wrote:
>> Hi,
> This is always a tricky thing to go about. Nicely human-readable doesn't imply nicely machine readable. Sometimes a single space or a single tab between values/columns is more practical for a(nother) program to read, but not for humans.
> So I will work from the assummption that you want it human-readable only.
> In that case, have a careful read through the string formatting options: http://docs.python.org/library/stdtypes.html#string-formatting
> Before the two tables there, there's a point 4 which mention a minimum field width; that'd be something you could use. Eg:
>>>> print "|%20d|" % 10
> | 10|
>>>> print "|%20.5f|" % 12.3456789
> | 12.34568|
>>>>
>
> Hopefully that gets you on the way.
>
> Cheers,
>
> Evert
>
>
Note that string formatting referenced above is old style, new style can
be found here http://docs.python.org/library/string.html#formatexamples
--
Cheers.
Mark Lawrence.
More information about the Tutor
mailing list