0
How do I import a module made by me
I can't import from module made by my own, it's simple code but I want to know how to import from my modules, in book says with script and extension .py I import module, but when I call it says that this module don't existing
2 Réponses
+ 5
I'm assuming you mean a project on your PC and not here on SL.
You have to take into account your project structure and the location of the module you wish to import.
if it looks like below where the files are next to each other
project_directory/
main.py
module.py
in the main.py
import module
if the module is in a sub-package directory
project_directory/
main.py
pacakge_directory/
module.py
import package_directory.module
This dot notation would extend to any further sub-packages as well
project_directory/
main.py
pacakge_directory_1/
module.py
pacakge_directory_2/
module.py
import package_directory_1.package_directory_2.module
if the module is elsewhere on your PC then you'd need to either add the direct path of the module to the import statement or the relative path.
Otherwise, if the module located within another place, such as the python install location, that is searched by the compiler then a standard import should work.
import module
+ 1
Uff, easy 🤣🤣🤣 thanks