[Python-Dev] More optimisation ideas
Terry Reedy
tjreedy at udel.edu
Mon Feb 1 22:44:34 EST 2016
On 2/1/2016 3:39 PM, Andrew Barnert via Python-Dev wrote:
> There are already multiple duplicate questions every month on
> StackOverflow from people asking "how do I find the source to stdlib
> module X". The canonical answer starts off by explaining how to
> import the module and use its __file__, which everyone is able to
> handle.
Perhaps even easier: start IDLE, hit Alt-M, type in module name as one
would import it, click OK. If Python source is available, IDLE will
open in an editor window. with the path on the title bar.
If we have to instead explain how to work out the .py name
> from the qualified module name, how to work out the stdlib path from
> sys.path, and then how to find the source from those two things, with
> the caveat that it may not be installed at all on some platforms, and
> how to make sure what they're asking about really is a stdlib module,
> and how to make sure they aren't shadowing it with a module elsewhere
> on sys.path, that's a lot more complicated.
The windows has the path on the title bar, so one can tell what was loaded.
IDLE currently uses imp.find_module (this could be updated), with a
backup of __import__(...).__file__, so it will load non-stdlib files
that can be imported.
> Finally, on Linux and Mac, the stdlib will usually be somewhere
> that's not user-writable
On Windows, this depends on the install location. Perhaps there should
be an option for edit-save or view only to avoid accidental changes.
--
Terry Jan Reedy
More information about the Python-Dev
mailing list