&gt;&gt;&gt; class RT(object):<br>...&nbsp;&nbsp;&nbsp;&nbsp; def Evaluate(self, code):<br>...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; eval(code, {&#39;test&#39;: self.test})<br>...&nbsp;&nbsp;&nbsp;&nbsp; def test(self):<br>...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &#39;RT test&#39;<br>...<br>&gt;&gt;&gt; RT().Evaluate(&#39;test()&#39;)<br>
RT test<br>&gt;&gt;&gt;<br><br><br><br><br><div class="gmail_quote">2008/6/27 Michael Foord &lt;<a href="mailto:fuzzyman@voidspace.org.uk">fuzzyman@voidspace.org.uk</a>&gt;:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">Michael Stephens wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I guess I can rebind locals and functions into my own dictionary.. I was just hoping to avoid that with some snazzy python.<br>
<br>
</blockquote></div>
I think exec&#39;ing in a custom context is *more* snazzy Python. :-p<br><font color="#888888">
<br>
Michael<br>
<br>
</font><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="Ih2E3d">
Michael Stephens<br>
<br>
Electrical Engineering Graduate Student<br>
University of Wyoming<br>
<a href="mailto:falcon@uwyo.edu" target="_blank">falcon@uwyo.edu</a> &lt;mailto:<a href="mailto:falcon@uwyo.edu" target="_blank">falcon@uwyo.edu</a>&gt; or <a href="mailto:89iroc@gmail.com" target="_blank">89iroc@gmail.com</a> &lt;mailto:<a href="mailto:89iroc@gmail.com" target="_blank">89iroc@gmail.com</a>&gt;<br>

<br></div><div class="Ih2E3d">
On Fri, Jun 27, 2008 at 10:58 AM, Michael Foord &lt;<a href="mailto:fuzzyman@voidspace.org.uk" target="_blank">fuzzyman@voidspace.org.uk</a> &lt;mailto:<a href="mailto:fuzzyman@voidspace.org.uk" target="_blank">fuzzyman@voidspace.org.uk</a>&gt;&gt; wrote:<br>

<br>
 &nbsp; &nbsp;Michael Stephens wrote:<br>
<br></div><div class="Ih2E3d">
 &nbsp; &nbsp; &nbsp; &nbsp;Closer.. but self.__dict__ is empty and cannot find test. &nbsp;We<br>
 &nbsp; &nbsp; &nbsp; &nbsp;are trying to wire up property expressions in our system. &nbsp; So<br>
 &nbsp; &nbsp; &nbsp; &nbsp;control.Enable=&quot;GetEnabled()&quot; rather than what we have now<br>
 &nbsp; &nbsp; &nbsp; &nbsp;which is control.Enable=&quot;currentform.GetEnabled()&quot;<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;I thought I could eval the RHS inside the class to get what i<br>
 &nbsp; &nbsp; &nbsp; &nbsp;wanted but alas no dice.<br>
<br>
<br>
 &nbsp; &nbsp;Well, you could do it in RT.__dict__ - but you would have to make<br>
 &nbsp; &nbsp;test a staticmethod.<br>
<br>
 &nbsp; &nbsp;Why not maintain an explicit dictionary as a context?<br>
<br>
 &nbsp; &nbsp;Michael<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;Michael Stephens<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;Electrical Engineering Graduate Student<br>
 &nbsp; &nbsp; &nbsp; &nbsp;University of Wyoming<br>
 &nbsp; &nbsp; &nbsp; &nbsp;<a href="mailto:falcon@uwyo.edu" target="_blank">falcon@uwyo.edu</a> &lt;mailto:<a href="mailto:falcon@uwyo.edu" target="_blank">falcon@uwyo.edu</a>&gt;<br></div><div class="Ih2E3d">
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;mailto:<a href="mailto:falcon@uwyo.edu" target="_blank">falcon@uwyo.edu</a> &lt;mailto:<a href="mailto:falcon@uwyo.edu" target="_blank">falcon@uwyo.edu</a>&gt;&gt; or<br>
 &nbsp; &nbsp; &nbsp; &nbsp;<a href="mailto:89iroc@gmail.com" target="_blank">89iroc@gmail.com</a> &lt;mailto:<a href="mailto:89iroc@gmail.com" target="_blank">89iroc@gmail.com</a>&gt;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;mailto:<a href="mailto:89iroc@gmail.com" target="_blank">89iroc@gmail.com</a> &lt;mailto:<a href="mailto:89iroc@gmail.com" target="_blank">89iroc@gmail.com</a>&gt;&gt;<br>
<br></div><div><div></div><div class="Wj3C7c">
 &nbsp; &nbsp; &nbsp; &nbsp;On Fri, Jun 27, 2008 at 10:46 AM, Michael Foord<br>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;<a href="mailto:fuzzyman@voidspace.org.uk" target="_blank">fuzzyman@voidspace.org.uk</a> &lt;mailto:<a href="mailto:fuzzyman@voidspace.org.uk" target="_blank">fuzzyman@voidspace.org.uk</a>&gt;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;mailto:<a href="mailto:fuzzyman@voidspace.org.uk" target="_blank">fuzzyman@voidspace.org.uk</a><br>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;mailto:<a href="mailto:fuzzyman@voidspace.org.uk" target="_blank">fuzzyman@voidspace.org.uk</a>&gt;&gt;&gt; wrote:<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Michael Stephens wrote:<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; I want to be able to execute arbitrary expressions but have<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; their context be within my class. &nbsp;The end result is<br>
 &nbsp; &nbsp; &nbsp; &nbsp;that RT<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; test should be printed and not global test<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; def test():<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;print &quot;global test&quot;<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; class RT:<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;def test(_self_):<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;print &#39;RT test&#39;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;def Evaluate(_self_,code):<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;eval(code)<br>
<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exec code in self.__dict__<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Might work.<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Michael<br>
<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; test()<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a.test()<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a=RT()<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a.Evaluate(&#39;test()&#39;)<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Michael Stephens<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Electrical Engineering Graduate Student<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; University of Wyoming<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="mailto:falcon@uwyo.edu" target="_blank">falcon@uwyo.edu</a> &lt;mailto:<a href="mailto:falcon@uwyo.edu" target="_blank">falcon@uwyo.edu</a>&gt;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;mailto:<a href="mailto:falcon@uwyo.edu" target="_blank">falcon@uwyo.edu</a> &lt;mailto:<a href="mailto:falcon@uwyo.edu" target="_blank">falcon@uwyo.edu</a>&gt;&gt;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;mailto:<a href="mailto:falcon@uwyo.edu" target="_blank">falcon@uwyo.edu</a> &lt;mailto:<a href="mailto:falcon@uwyo.edu" target="_blank">falcon@uwyo.edu</a>&gt;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;mailto:<a href="mailto:falcon@uwyo.edu" target="_blank">falcon@uwyo.edu</a> &lt;mailto:<a href="mailto:falcon@uwyo.edu" target="_blank">falcon@uwyo.edu</a>&gt;&gt;&gt; or<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="mailto:89iroc@gmail.com" target="_blank">89iroc@gmail.com</a> &lt;mailto:<a href="mailto:89iroc@gmail.com" target="_blank">89iroc@gmail.com</a>&gt;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;mailto:<a href="mailto:89iroc@gmail.com" target="_blank">89iroc@gmail.com</a> &lt;mailto:<a href="mailto:89iroc@gmail.com" target="_blank">89iroc@gmail.com</a>&gt;&gt;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;mailto:<a href="mailto:89iroc@gmail.com" target="_blank">89iroc@gmail.com</a> &lt;mailto:<a href="mailto:89iroc@gmail.com" target="_blank">89iroc@gmail.com</a>&gt;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;mailto:<a href="mailto:89iroc@gmail.com" target="_blank">89iroc@gmail.com</a> &lt;mailto:<a href="mailto:89iroc@gmail.com" target="_blank">89iroc@gmail.com</a>&gt;&gt;&gt;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  &nbsp; &nbsp; &nbsp; &nbsp; ------------------------------------------------------------------------<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _______________________________________________<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Users mailing list<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;mailto:<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a>&gt;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;mailto:<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;mailto:<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a>&gt;&gt;<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- &nbsp; &nbsp;<a href="http://www.ironpythoninaction.com/" target="_blank">http://www.ironpythoninaction.com/</a><br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.voidspace.org.uk/" target="_blank">http://www.voidspace.org.uk/</a><br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.trypython.org/" target="_blank">http://www.trypython.org/</a><br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.ironpython.info/" target="_blank">http://www.ironpython.info/</a><br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.theotherdelia.co.uk/" target="_blank">http://www.theotherdelia.co.uk/</a><br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.resolverhacks.net/" target="_blank">http://www.resolverhacks.net/</a><br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _______________________________________________<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Users mailing list<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;mailto:<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a>&gt;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;mailto:<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br></div></div><div><div></div><div class="Wj3C7c">
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;mailto:<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a>&gt;&gt;<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;------------------------------------------------------------------------<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;_______________________________________________<br>
 &nbsp; &nbsp; &nbsp; &nbsp;Users mailing list<br>
 &nbsp; &nbsp; &nbsp; &nbsp;<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a> &lt;mailto:<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a>&gt;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
 &nbsp; &nbsp; &nbsp; &nbsp; <br>
<br>
<br>
 &nbsp; &nbsp;--  &nbsp; &nbsp;<a href="http://www.ironpythoninaction.com/" target="_blank">http://www.ironpythoninaction.com/</a><br>
 &nbsp; &nbsp;<a href="http://www.voidspace.org.uk/" target="_blank">http://www.voidspace.org.uk/</a><br>
 &nbsp; &nbsp;<a href="http://www.trypython.org/" target="_blank">http://www.trypython.org/</a><br>
 &nbsp; &nbsp;<a href="http://www.ironpython.info/" target="_blank">http://www.ironpython.info/</a><br>
 &nbsp; &nbsp;<a href="http://www.theotherdelia.co.uk/" target="_blank">http://www.theotherdelia.co.uk/</a><br>
 &nbsp; &nbsp;<a href="http://www.resolverhacks.net/" target="_blank">http://www.resolverhacks.net/</a><br>
<br>
 &nbsp; &nbsp;_______________________________________________<br>
 &nbsp; &nbsp;Users mailing list<br>
 &nbsp; &nbsp;<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a> &lt;mailto:<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a>&gt;<br>
 &nbsp; &nbsp;<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
<br>
<br>
------------------------------------------------------------------------<br>
<br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
 &nbsp;<br>
</div></div></blockquote><div><div></div><div class="Wj3C7c">
<br>
<br>
-- <br>
<a href="http://www.ironpythoninaction.com/" target="_blank">http://www.ironpythoninaction.com/</a><br>
<a href="http://www.voidspace.org.uk/" target="_blank">http://www.voidspace.org.uk/</a><br>
<a href="http://www.trypython.org/" target="_blank">http://www.trypython.org/</a><br>
<a href="http://www.ironpython.info/" target="_blank">http://www.ironpython.info/</a><br>
<a href="http://www.theotherdelia.co.uk/" target="_blank">http://www.theotherdelia.co.uk/</a><br>
<a href="http://www.resolverhacks.net/" target="_blank">http://www.resolverhacks.net/</a><br>
<br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
</div></div></blockquote></div><br>