2

Python version: 2.7.12

I created my own module which is called mymodule.py. I put the module inside the mymodule directory, so:

mymodule/
  __init__.py
  mymodule.py

Additionally I checked the sys.path list and I moved whole mymodule/ to /usr/lib64/python2.7/site-packages/ where the numpy/ catalog is also located. When I run the python I can import mymodule in all these ways:

>>> import mymodule.mymodule
>>> from mymodule import mymodule
>>> from mymodule.mymodule import fun1, var1

I understand the hierarchy of files and catalogs. I know that mymodule/ is level up than mymodule, thus a dot operator is needed. But we can notice similar structure for the numpy/ catalog and in this case:

>>> import numpy

is enough to import this module, not:

>>> import numpy.numpy

I read the official documentation about modules and I can't find the answer. Of course I can put mymodule.py inside /usr/lib64/python2.7/site-packages/ but it could cause a mess. Moreover mymodule/ give me something like a namespace (someone else can create also mymodule.py file containing different statements).

Which way is recommended to publish own modules?

Benek
  • 91
  • 11
  • 2
    Here's an exercise. Go to the `numpy` package. Open the top level `__init__.py` file and look at what's in there. ;) – cs95 Jun 28 '17 at 07:54
  • Ah, screw it. Here it is: https://github.com/qsnake/numpy/blob/master/numpy/__init__.py – cs95 Jun 28 '17 at 07:55
  • 1
    Does this Q/A help https://stackoverflow.com/questions/1944569/how-do-i-write-good-correct-package-init-py-files – Jacques Kvam Jun 28 '17 at 08:17

0 Answers0