<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">All,<div><br></div><div>The problem is illustrated here:<div><br></div><div>This code will work properly:</div><div><br></div><div><a href="http://paste.pocoo.org/show/90071/">http://paste.pocoo.org/show/90071/</a></div><div><br></div><div>This code produces an error:</div><div><br></div><div><a href="http://paste.pocoo.org/show/90072/">http://paste.pocoo.org/show/90072/</a></div><div><br></div><div>Regards,</div><div>Ken</div><div><br><div><div>On Nov 4, 2008, at 4:42 AM, Michael Foord wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Kenneth Miller wrote:<br><blockquote type="cite">It was proven to me that while exec might work for simple cases, more advanced usage (declaring a lambda function inside an exec) can be problematic. It was advised that I generate python modules and dynamically import them. If memory served me, it's not possible to import a module from a string object.<br></blockquote><blockquote type="cite"><br></blockquote>I have often generated (or loaded code into a string) and then exec'd it into a module dict to create modules at runtime. It is a relatively normal technique in Python.<br><br>Michael<br><br><blockquote type="cite">Thanks.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">- Ken<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">On Nov 4, 2008, at 12:45 AM, "Curt Hagenlocher" &lt;<a href="mailto:curt@hagenlocher.org">curt@hagenlocher.org</a> &lt;<a href="mailto:curt@hagenlocher.org">mailto:curt@hagenlocher.org</a>>> wrote:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><blockquote type="cite">You should be able to do this all in-memory:<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">>>> import sys<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">>>> foo = type(sys)('foo')<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">>>> sys.modules['foo'] = foo<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">>>> exec 'a = 1' in foo.__dict__<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">>>> foo.a<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">1<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">>>><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">There's probably a better ("more Pythonic") way to do this, but I'm sleepy...<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">On Mon, Nov 3, 2008 at 11:40 PM, Kenneth Miller &lt;<a href="mailto:xkenneth@gmail.com">xkenneth@gmail.com</a> &lt;<a href="mailto:xkenneth@gmail.com">mailto:xkenneth@gmail.com</a>>> wrote:<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> &nbsp;&nbsp;&nbsp;All,<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Is it possible to have python load modules from the silverlight<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> &nbsp;&nbsp;&nbsp;isolated storage? My app needs to dynamically generate and import<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> &nbsp;&nbsp;&nbsp;python code to run.<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> &nbsp;&nbsp;&nbsp;Regards,<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> &nbsp;&nbsp;&nbsp;Ken<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> &nbsp;&nbsp;&nbsp;_______________________________________________<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> &nbsp;&nbsp;&nbsp;Users mailing list<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> &nbsp;&nbsp;&nbsp;<a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a> &lt;<a href="mailto:Users@lists.ironpython.com">mailto:Users@lists.ironpython.com</a>><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"> &nbsp;&nbsp;&nbsp;<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">_______________________________________________<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">Users mailing list<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a> &lt;<a href="mailto:Users@lists.ironpython.com">mailto:Users@lists.ironpython.com</a>><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br></blockquote></blockquote><blockquote type="cite">------------------------------------------------------------------------<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">_______________________________________________<br></blockquote><blockquote type="cite">Users mailing list<br></blockquote><blockquote type="cite"><a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br></blockquote><blockquote type="cite"><a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br></blockquote><blockquote type="cite"> &nbsp;<br></blockquote><br><br>-- <br><a href="http://www.ironpythoninaction.com/">http://www.ironpythoninaction.com/</a><br><a href="http://www.voidspace.org.uk/blog">http://www.voidspace.org.uk/blog</a><br><br><br>_______________________________________________<br>Users mailing list<br>Users@lists.ironpython.com<br>http://lists.ironpython.com/listinfo.cgi/users-ironpython.com<br></div></blockquote></div><br></div></div></body></html>