evalstr
Joonas Paalasmaa
joonas.paalasmaa at nokia.com
Wed Jul 11 06:30:07 EDT 2001
Shannon --jj Behrens wrote:
>
> Hello All,
>
> I wrote a useful C module for doing string
> interpolation. I find it indespensible when working
> with large blocks of triple-quoted text. When working
> with large blocks of triple-quoted text, nothing else
> is quite as convenient. Here's the Python doc:
[lots of text snipped]
> Please forgive my arrogance, but I think that it might
> even be useful enough to be included as a standard
> module. If, not perhaps you guys might have some
> suggestions as to what I can do with it. You may
> download the entire packages from:
>
> <http://ironorchid.com/jjinux/evalstr.tar.gz>
I prefer the following method for evaluations inside strings.
>>> class Eval:
def __getitem__(self, key):
return eval(key)
>>> foo = 3.0
>>> spam = 5.0
>>> print "%(foo/spam)s" % Eval()
0.6
>>> print "%(foo/spam).55f" % Eval()
0.5999999999999999800000000000000000000000000000000000000
>>>
More information about the Python-list
mailing list