[Tutor] Formatter

Don Arnold darnold02@sprynet.com
Sun Jan 19 11:26:01 2003


----- Original Message -----
From: "Pete Versteegen" <pversteegen@gcnetmail.net>
To: "Don Arnold" <darnold02@sprynet.com>; <Tutor@python.org>
Cc: "andy surany" <mongo57a@comcast.net>
Sent: Sunday, January 19, 2003 9:49 AM
Subject: Re: [Tutor] Formatter


>
> Thanks folks for helping me on the formatter issue!  That gives me a great
> start and it showed me how to solve problems of this nature with Python.
> There are a couple of other field descriptors that I would like to
> incorporate, e.g., exponential notation, 1.2345e-01, and octal
> representation, and creating records that are subsequently written to
other
> files.  I enjoy reading the questions and answers and rebuttals on the
list.
>

While seeing how to decode a 'roll your own' format string is an interesting
exercise, we definitely are reinventing the wheel here. All this code really
does is translate your format specifier scheme into Python's own. As Magnus
pointed out, you really should take a look at
http://www.python.org/doc/current/lib/typesseq-strings.html . It lists all
of the string formatting specifiers that Python uses.

scientific notation:

>>> '%20.5e' % .045678957
'        4.56790e-002'

octal:

>>> '%10o' % 4096
'     10000'


>
> Pete
> pversteegen@gcnetmail.net

HTH,
Don