Modules
Not met yet
Any .py file is a module, and its name is the file name without .py. import hours runs hours.py once and gives you its names as hours.is_open; from hours import is_open brings in just that one name, used on its own. Write a helper once in a module and import it everywhere. Never give a variable the same name as a module you've imported.
Try it
main.pyOutput
Press Run and what your program prints shows up here.
Easy to get wrong
- Thinks importing a module a second time runs its code again.
- Thinks giving a variable the same name as an imported module leaves the module still usable.
- Thinks a name brought in with from ... import still needs the module's name in front of it.