Python modules 🤦 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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.

17th Aug 2021, 6:35 AM
Pardha Saradhi
2 Answers
+ 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
17th Aug 2021, 7:54 AM
Iftekhar Ahmed Pranto
Iftekhar Ahmed Pranto - avatar
+ 2
You can't use your module if in standard library exist module with same name, so you should rename file
17th Aug 2021, 7:46 AM
Roma Butaku
Roma Butaku - avatar