On 04Feb2017 10:13, Ben Finney <ben+pyt...@benfinney.id.au> wrote:
Neal Becker <ndbeck...@gmail.com> writes:
I want to make sure any modules I build in the current directory
overide any others. To do this, I'd like sys.path to always have './'
at the beginning.

The ‘sys.path’ list is used only for *absolute* imports. Modules in the
current directory should not be imported with an absolute path[0]. So, the
current directory should not be in ‘sys.path’.

So, for the past ten years and more, Python supports import of modules
from the current directory with an explicit *relative* path::

   # Absolute imports, searching ‘sys.path’.
   import datetime
   from collections import namedtuple

   # Relative imports, starting from this module's directory.
   from . import foo
   from .bar import baz

See <URL:https://www.python.org/dev/peps/pep-0328/>, in particular
<URL:https://www.python.org/dev/peps/pep-0328/#guido-s-decision>.

I wrote:
Yes, I know Python likes to search
the current directory for modules, notmy favourite feature.

I stand corrected.

Cheers,
Cameron Simpson <c...@zip.com.au>
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to