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 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> <<a href="mailto:sanxiyn@gmail.com">sanxiyn@gmail.com</a>> 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 <<a href="mailto:garys@ihug.com.au">garys@ihug.com.au</a>>:<br>> I started off trying to use standard "compile()" function and "exec"<br>> statement, but was unable to make it work, although I'm sure there must be a
<br>> 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>>>> code = "def add(x, y):\n\treturn x + y\n"
<br>>>> exec code<br>>>> 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>"Peace is its own reward." - Mahatma Gandhi