string issue or questions about intern

Bjorn Pettersen bjorn at roguewave.com
Fri Jul 14 20:23:09 EDT 2000


Paul Prescod wrote:
> 
> Andrew Kuchling wrote:
> >
> > ...
> >
> > If you need full Python expressions, there seems no way around using
> > eval().  But if you simply need string escapes, it's probably worth
> > writing a parser.  (Does such a parser already exist somewhere in the
> > standard library?  Anyone know?)
> 
> In general, wouldn't it be nice if there was a parser for all Python
> literal syntaxes? Sometimes its really convenient to keep your data in a
> format like this:
> 
> {"a":"b"}
> 
> but I cringe to load the file and then eval it for security reasons.

Do you want something like (from the python2c distribution)?:

D:\bjorn\py2c>python
Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import transformer
>>> t = transformer.Transformer()
>>> t.parseexpr("""{'a':'b'}""")
('dict', [(('const', 'a'), ('const', 'b'))])


-- bjorn




More information about the Python-list mailing list