I am currently doing a personal coding project and I am trying to build a module, but I don't know why my structure doesn't work the way it's supposed to:
\mainModule
__init__.py
main.py
\subModule_1
__init__.py
someCode_1.py
someCode_2.py
\subModule_2
__init__.py
otherCode.py
I want to be able to run the following code from main.py:
>>> from subModule_1 import someCode_1
>>> someCode_1.function()
"Hey, this works!"
>>> var = someCode_2.someClass("blahblahblah")
>>> var.classMethod1()
>>> "blah blah blah"
>>> from subModule2 import otherCode
>>> otherCode("runCode","#ff281ba0")
However, when I try to import someCode_1, for example, it returns an AttributeError, and I'm not really sure why. Is it to do with the __init__.py file?
REVISIONS
Minimal, Complete and verifiable (I hope...)
\mainDir __init__.py # blank file main.py \subDir __init__.py # blank file codeFile.pyUsing this...
#main.py file import subDir subDir.codeFile.function()And this...
#codeFile.py file def function(): return "something"...it returns the same problem mentioned above**.
** The exact error is:
Traceback (most recent call last):
File "C:\...\mainDir\main.py", line 2, in <module>
subDir.codeFile.function()
AttributeError: module 'subDir' has no attribute 'codeFile'
Credits to @jonrsharpe: Thanks for showing me how to use Stack Overflow correctly.
main.py", which doesn't entirely make sense.someCode_1which is executed upon import. WHat is the exact error message?main.pyusing the interpreter (sorry, rookie mistake)Traceback (most recent call last): File "C:\...\main.py", line 10, in <module> subDir.codeFile.function() AttributeError: module 'subDir' has no attribute 'codeFile'mainDirnorsubDirwhen you perform the test.