-4

how to create submodule in python? Thanks! I need write _init__.py? It name will be pybase

tohatsu
  • 115
  • 9

1 Answers1

0

A folder with .py files and a init.py is called a package. One of those files containing classes and functions is a module. Folder nesting can give you subpackages.

So for example if I had the following structure:

mypackage
__init__.py
module_a.py
module_b.py
mysubpackage
__init__.py
module_c.py
module_d.py

I could import mypackage.module_a or mypackage.mysubpacakge.module_c and so on.

You could also add functions to mypackage (like the numpy functions you mentioned) by placing that code in the init.py. Though this is usually considered to be ugly.

If you look at numpy's init.py you will see a lot of code in there - a lot of this is defining these top-level classes and functions. The init.py code is the first thing executed when the package is loaded.

tohatsu
  • 115
  • 9