use strings to call functions

Stephen Hansen apt.shansen at gmail.com
Tue Feb 9 01:26:11 EST 2010


On Mon, Feb 8, 2010 at 10:00 PM, OdarR <olivier.darge at gmail.com> wrote:

> On 9 fév, 02:50, Jean-Michel Pichavant <jeanmic... at sequans.com> wrote:
> > Aahz wrote:
> > > In article <
> 0efe23a6-b16d-4f92-8bc0-12d056bf5... at z26g2000yqm.googlegroups.com>,
> > > OdarR  <olivier.da... at gmail.com> wrote:
> >
> > >> and with eval(), did you try ?
> >
> > > WARNING: eval() is almost always the wrong answer to any question
> >
> > Some say that eval is evil !
> >
> > JM
>
> go to hell ;-), it is part of the language, it seems to match the
> aforementioned question.
>
> I don't see it as a problem.
>

Yes, it is a part of the language, because as a dynamic language has to have
such a capability.

Because there are legitimate use-cases for it.

But they are extremely rare.

Extremely rare.

But it is there: if there is a real, legitimate use-case for a feature that
can't be solved by other means, then certainly include a feature to
accomplish that goal.

But that doesn't mean you use that feature all over just because its there.
You use it when its appropriate. The ability to do a thing doesn't mean you
should do a thing.

In most cases, eval is not appropriate. It might do what you think you want,
but often there are huge consequences and not at all obvious considerations
you have to take into account.

Usually when you think you want to eval, there's a better way to approach
the problem. It might not seem right away to be as "easy" or "seamless" as
you think you want, but there are almost always compelling reasons why its
better, easier, more efficient and simpler.

People are trying to help the OP not only by providing the easiest approach
to solve a problem, but trying to show him the best way to make /good code/.
Good Code isn't a purely subjective thing left up to idle taste.

...

Also? "go to hell" even with a smiley is being an asshat.

Don't be an asshat.

--S
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100208/9095badb/attachment-0001.html>


More information about the Python-list mailing list