<div dir="ltr"><div>I don't know whether it's worth the savings, but the __code__ for a module's toplevel is thrown away because it is not needed after it has run. Reading it back from disk is wasteful if you do it every time for every module, but how often is it used in a situation where speed matters?<br>
<br></div>Saving __code__ might be useful so you can tell with certainty which code was run -- the file may have been modified since it was imported.<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Mar 17, 2014 at 10:11 AM, Antoine Pitrou <span dir="ltr"><<a href="mailto:solipsis@pitrou.net" target="_blank">solipsis@pitrou.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">On Tue, 18 Mar 2014 02:36:31 +1000<br>
Nick Coghlan <<a href="mailto:ncoghlan@gmail.com">ncoghlan@gmail.com</a>> wrote:<br>
> On 18 Mar 2014 01:59, "C Anthony Risinger" <<a href="mailto:anthony@xtfx.me">anthony@xtfx.me</a>> wrote:<br>
> ><br>
> > ok, let me try this again, sans distractions:<br>
> ><br>
> > could we consider adding __code__ and __call__ to module objects?<br>
> __code__ would contain the code executed in the module __dict__, and<br>
> __call__ would reload the module.<br>
> ><br>
> > thoughts?<br>
><br>
> The question to ask is: what would such a change make possible that<br>
> importlib doesn't already handle?<br>
<br>
</div>I suppose module.__code__ would be a lot less wasteful than<br>
module.__loader__.get_code(module.__name__) (which seems to reload the<br>
bytecode from disk every time).<br>
<br>
(while looking at this, I was surprised that dis.dis(some_module)<br>
1) doesn't show a disassembly for the module toplevel 2) shows<br>
disassembly for objects which some_module imports from other modules)<br>
<br>
Regards<br>
<span class="HOEnZb"><font color="#888888"><br>
Antoine.<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>--Guido van Rossum (<a href="http://python.org/~guido">python.org/~guido</a>)
</div>