Embedding questions
Fredrik Lundh
fredrik at pythonware.com
Fri Dec 10 06:08:06 EST 1999
Olaf Appelt <tholap at compuserve.com> wrote:
> > ...snipped out request for averloading assignment
> >
> > > but that would look rather ugly:
> >
> > > c.assign (a + b)
> >
> > Or you could go on and really abuse the language
>
> Shall I take that as a recommendation that I shouldn't use Python for what I
> need?
nope. you should think a bit more about your
original problem.
if I understand things correctly, you want to
set a variable to something, execute some user
code, and then inspect that variable. right?
okay, here's how to do that:
c = "my value"
namespace = {}
namespace["c"] = c
exec usercode in namespace
c = namespace["c"]
print c
in other words, let the user change "c" to whatever
he/she wants, and pick up the result afterwards. if
it's not the right type, convert it (if that's a reason-
able thing to do). otherwise, complain to the user.
</F>
More information about the Python-list
mailing list