0
Python modules 🤦
I created a module called math.py in my working directory. We have a predefined math module. Here I want to perform a small test. When I import math in my main.py, it collects data from predefined math module then what about my math module which I created? How can I access it? Please anyone help. I don't want to change my module name. I want to know what is happening here.
3 Respostas
+ 4
Since 2 module can’t have same name. You can rename your module somthing uncommon. Then use “as” to rename it.
// m_ath.py
import m_ath as math
Or, I have found another solution.
# some_file.py
import sys
# insert at 1, 0 is the script path (or '' in REPL)
sys.path.insert(1, '/path/to/application/app/folder')
import file
+ 2
You can't use your module if in standard library exist module with same name, so you should rename file