Exec and Scope

James Mills prologic at shortcircuit.net.au
Thu Oct 30 23:56:02 EDT 2008


Manu,

Good lord man, what are you trying to solve ?
Describe your "actual problem" you're attempting
to solve... This looks really really ugly and I would
advise against any solution that relies on exec()

--JamesMills

On Fri, Oct 31, 2008 at 1:47 PM, Emanuele D'Arrigo <manu3d at gmail.com> wrote:
> Hi everybody!
>
> I'm trying to do something in a way that is probably not particularly
> wise but at this point I don't know any better, so bear with me.
>
> Suppose in main.py I have the following statements:
>
> myObject = MyObject()
> execThis("myObject.myCommand()")
>
> Now suppose the method
>
> def execThis(aCommandInAString):
>    exec(aCommandInAString)
>
> is somewhere "far away" in terms of scope. Somewhere where the code
> doesn't know anything about the instance myObject and even less about
> its methods and attributes. How do I get myObject.myCommand() properly
> executed?
>
> I'm guessing it's about taking a snapshot of or a reference to the
> namespace that is correct for the execution of the command, but... is
> that the case? And how do I get a handle to that?
>
> Thanks for your help!
>
> Manu
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
--
-- "Problems are solved by method"



More information about the Python-list mailing list