evalstr

Joonas Paalasmaa joonas.paalasmaa at nokia.com
Wed Jul 11 18:01:42 CEST 2001


Steve Holden wrote:
> 
> "Joonas Paalasmaa" <joonas.paalasmaa at nokia.com> wrote in message
> news:3B4C2A0E.60AA094 at nokia.com...
> > 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
> 
> That's a very neat trick. Had you though of writing it up as a Python
> recipe?
> 
To where?



More information about the Python-list mailing list