0

I'm going mad about creating a module in Python:

Say I'm calling it "my_module"

I've created a folder called "my_module", in which I've put "setup.py" and all the other files required for the installation and manteinance.

Then inside my_module folder I created another folder called, again, my_module, inside of which I put the * init.py file and some other files like foo.py, foo2.py

What I really don't understand is why now I have to call

from my_module.my_module.foo import ...

instead of

from my_module.foo import ...

Does anybody know where am I getting this wrong?

Stefano Frassetto
  • 108
  • 2
  • 2
  • 9
  • 1
    Because you have 2 my_module folders? That seems expected to me. – user3483203 Mar 05 '18 at 23:02
  • well thing doesn change even if I call the top folder "my_top_folder", I will have to import my_top_folder.my_module.foo again... Shouldn't the module live inside within the folder where I created the __init__.py file? – Stefano Frassetto Mar 05 '18 at 23:04
  • 1
    Again, that seems like expected behavior. my_module does not have a file called foo inside of it, it just has an additional folder called my_module inside of it. – user3483203 Mar 05 '18 at 23:05
  • 2
    Python searches for modules from `sys.path`. Print that out and see which top level directory it will search from. If `my_top_folder` is not there then it would need to be specified. – cdarke Mar 05 '18 at 23:07
  • thanks @cdarke, this behavior was unfamiliar to me – Stefano Frassetto Mar 05 '18 at 23:12

0 Answers0