[Python-Dev] features i'd like [Python 3000?] ... #4: interpolated strings ala perl
Josiah Carlson
jcarlson at uci.edu
Thu Dec 7 23:19:58 CET 2006
"Alexey Borzenkov" <snaury at gmail.com> wrote:
> It can even be simpler and more powerful:
>
> class evallookup:
> def __init__(self, nsg, nsl):
> self.nsg = nsg
> self.nsl = nsl
> def __getitem__(self, name):
> return eval(name, self.nsg, self.nsl)
Never use eval in any code where you don't have 100% control of the
content of what is being evaluated. And even then, never use eval.
It doesn't make a difference in the earlier example, but I'm sure there
are ways of breaking the above in nasty ways.
- Josiah
More information about the Python-Dev
mailing list