[Python-ideas] Pseudo-package for current directory

Chris Angelico rosuav at gmail.com
Mon Mar 7 19:44:26 EST 2016


On Tue, Mar 8, 2016 at 11:32 AM, Rob Cliffe <rob.cliffe at btinternet.com> wrote:
> Sorry if I'm belabouring the point, I should have included this in my last
> e-mail.
> But you seem to be saying that when I write
>     import xyz
> and I mean "import xyz from the current directory, not from the stdlib [or
> whatever]"
> I have to know the names of all the modules in the stdlib [or whatever].
> Or else *always* add some boilerplate whenever I mean "import from the
> current directory".  Well, maybe, but I am sure a lot of the time I couldn't
> be bothered, and then some day I'd run into a not-immediately-obvious bug.
> I.e.: Changing the current behaviour would surprise me.

Which is exactly why I am NOT proposing changing the default behaviour
(at least, not any time soon). If you're prepared to accept that
"import xyz" will only import from sys.path (which would then not have
the script directory in it), then you enable this option, otherwise
you don't. When you want that, you say "from . import xyz", and all
works as you would expect.

ChrisA


More information about the Python-ideas mailing list