New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module import precedence mistake in the Python imports article #2

etene opened this Issue Apr 27, 2018 · 1 comment


None yet
2 participants
Copy link

etene commented Apr 27, 2018


First of all excuse me if this isn't the right place to post this, i didn't really know how to get in touch so I figured a Github issue would be the best way to do it.

I was reading your post regarding imports (, which I found instructive & well written, but there's a small point I think is wrong.

Here's the excerpt:

The Python documentation goes on to mention the following:

The directory containing the script being run is placed at the beginning of the search path, ahead of the standard library path. This means that scripts in that directory will be loaded instead of modules of the same name in the library directory.

This seems to be a mistake. For example, calling import math in will import the standard math module, NOT my own file in the same directory.

The documentation is correct: the described behavior applies to modules in the standard library directory. The math module is a builtin module (like the sys module), guaranteed to be always available, and thus not implemented as a separate Python file in the standard library.

If you name your own module argparse for example, it will indeed have precedence over the argparse module in the standard library.

Hope I was clear, and thanks again for your excellent post. Cheers !


This comment has been minimized.

Copy link

chrisyeh96 commented Apr 27, 2018

Thanks for pointing this out! I was unaware of the difference between built-in modules and other modules in Python's standard library until now. I have updated the post.

@chrisyeh96 chrisyeh96 closed this Apr 27, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment