PyWart: "Python's import statement and the history of external dependencies"

Rick Johnson rantingrickjohnson at
Fri Nov 21 16:52:34 CET 2014

On Friday, November 21, 2014 4:29:48 AM UTC-6, Tim Chase wrote:

> What messed-up version of Python are you running?  
> Or did you fail to test your conjecture?
> $ cat >
> print("This is my local")
> x=1
> $ cat >
> import calendar
> print(dir(calendar))
> $ python2 
> This is my local
> ['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'x']
> $ python3
> This is my local
> ['__builtins__', '__cached__', '__doc__', '__file__', '__name__', '__package__', 'x']
> It finds my local module, not the system "calendar" module.

You failed to provide the needed information!
  1. We need to see the values in sys.path. So print them
  directly before making the call to import.
  2. Where did you store your custom "" script?
Remember, "import" is an implicit mechanism, it works by
searching the values of 'sys.path' one-by-one (if the module
was not already loaded!) until the *FIRST* module matching
the name you requested is found. If the folder that holds
*your* custom "" script is listed *before* the
folder containing the "python calendar" modules then of
course your module will be correctly loaded.

More information about the Python-list mailing list