Skip to content

Modules

jasper-zanjani edited this page Aug 30, 2020 · 1 revision

When learning unfamiliar packages and importing them in a demonstration script, care must be taken that the demonstration script does not have the same name as the package being studied. If so, attempting to import the package while in an interpreter within that directory will cause the interpreter to try importing the incomplete script and not the package.

When running a Python interpreter within this directory, the files "calc" and "main" can be imported as modules by specifying their names with no file extension.

. 
├── calc.py 
└── main.py
import calc # No errors
import main # No errors

Specifying the full filename including extension does produce an error

import calc.py # Error
import main.py # Error

Clone this wiki locally