<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 29 December 2014 at 23:02, Chris Angelico <span dir="ltr"><<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="">On Mon, Dec 29, 2014 at 11:46 PM, Nick Coghlan <<a href="mailto:ncoghlan@gmail.com">ncoghlan@gmail.com</a>> wrote:<br>
> However, even today, it's not particularly difficult to create custom launch<br>
> scripts that initialise __main__ with a few different modules based on what<br>
> you plan to work on and then set os.environ["PYTHONINSPECT"] = "1" to drop<br>
> into the interactive interpreter:<br>
><br>
> $ python3 -c "import sys, os; os.environ['PYTHONINSPECT'] = '1'"<br>
>>>> sys, os<br>
> (<module 'sys' (built-in)>, <module 'os' from '/usr/lib64/python3.4/os.py'>)<br>
>>>><br>
<br>
</span>Once again, that's fine for sys and os, which won't take long to<br>
import. For this to work with _every_ module on the system, you'd need<br>
to couple it with a lazy import mechanism. We had some proposals along<br>
those lines recently... what happened to them?<br></blockquote><div><br></div></div>The infrastructure landed for 3.5 already, so the custom startup script can also register a lazy loader if it wants to do so: <a href="https://docs.python.org/dev/library/importlib.html#importlib.util.LazyLoader">https://docs.python.org/dev/library/importlib.html#importlib.util.LazyLoader</a><br><br></div><div class="gmail_extra">(Lazy loading is already possible, since it's just a particular way of using the existing import customisation mechanisms that have been around for over a decade, 3.5 just makes it easier by providing more of the infrastructure to do it directly in the standard library)<br><br></div><div class="gmail_extra">You can also fairly easily have different startup scripts for different scenarios, and then use explicit imports to bring in any extra pieces you decide you want for a given session.<br><br></div><div class="gmail_extra">One trick I'll sometimes use myself is to do my playing around in IPython Notebooks, where any common setup code can just go in the first cell. (I'm not sure if IPython Notebook has a "clone existing notebook" feature yet, but that would be a very nice way to have template environments with different setup cells)<br><br></div><div class="gmail_extra">New language features, or even default interpreter features, are generally an absolute last resort for solving problems - the vast majority of problems can be better solved externally. Incurring the long term maintenance costs of standardisation only makes sense when the perceived pay-off is deemed likely to justify that investment.<br></div><br><div class="gmail_extra">Cheers,<br>Nick.<br></div><div class="gmail_extra"><br>-- <br><div class="gmail_signature">Nick Coghlan   |   <a href="mailto:ncoghlan@gmail.com">ncoghlan@gmail.com</a>   |   Brisbane, Australia</div>
</div></div>