Import
PronunciationIM-port
Definition
Import is how you bring code from another module or package into the current file, so you can use its functions and classes.
Where you hear it
At the top of nearly every Python or JavaScript file, and in errors such as ImportError or circular imports.
Examples
Import only the names you need from the module.
A circular import happens when two modules import each other.
The report script imports the date helpers from the utils module.
Common mistake
Using from module import *. It hides where names come from and can overwrite your own.
Don't confuse with
Include or copy-paste, which duplicates code. Import refers to the original and loads it once.
Say it at work
- In a meeting or chat
Move that import inside the function to break the cycle.
- In an email or ticket
Group the imports: standard library first, then third-party, then ours.
Keep exploring
More in Programming Fundamentals