Alternatively, you can simply use the file object to write it to a new module and import it later. <br><br>newmod=file('newmodule.py','w')<br>newmod.write('def add(x,y):\n&nbsp;&nbsp;&nbsp; return x+y\n')<br>newmod.close()<br>import newmodule
<br>print newmodule.add(10,20)<br><br>Vagmi<br><br><div><span class="gmail_quote">On 9/18/06, <b class="gmail_sendername">Sanghyeon Seo</b> &lt;<a href="mailto:sanxiyn@gmail.com">sanxiyn@gmail.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
2006/9/18, Gary Stephenson &lt;<a href="mailto:garys@ihug.com.au">garys@ihug.com.au</a>&gt;:<br>&gt; I started off trying to use standard &quot;compile()&quot; function and &quot;exec&quot;<br>&gt; statement, but was unable to make it work, although I'm sure there must be a
<br>&gt; way. Is there? How?<br><br>This works for me:<br><br>IronPython 1.0.2449 on .NET 2.0.50727.42<br>Copyright (c) Microsoft Corporation. All rights reserved.<br>&gt;&gt;&gt; code = &quot;def add(x, y):\n\treturn x + y\n&quot;
<br>&gt;&gt;&gt; exec code<br>&gt;&gt;&gt; add(2, 3)<br>5<br><br>Seo Sanghyeon<br>_______________________________________________<br>users mailing list<br><a href="mailto:users@lists.ironpython.com">users@lists.ironpython.com
</a><br><a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br></blockquote></div><br><br clear="all"><br>-- <br><a href="http://geekswithblogs.net/vagmi.mudumbai">
http://geekswithblogs.net/vagmi.mudumbai</a><br><a href="http://installneo.blogspot.com">http://installneo.blogspot.com</a><br><br>&quot;Peace is its own reward.&quot; - Mahatma Gandhi