Posts

Showing posts from September, 2018

Creating a package in Python

Make a package root directory $work_dir=/tmp mkdir $work_dir/my_py_pakage touch  $work_dir/my_py_pakage/__init__.py  my_py_pakage is a package; init file that makes the package a python module  If a path is not in sys.path, add it import sys sys.path.append('/tmp') Now you can import your package import mypackage type(mypackage) <class module> dir(mypackage) ['__builtins__',  '__cached__',  '__doc__',  '__file__',  '__loader__',  '__name__',  '__package__',  '__path__',  '__spec__'] See some information for you  module mypackage.__file__ mypackage.__path__ mypackage.__specs__ -packages are a special type of module -unlike normal module, packages can contain other modules and other packages -package has __path__ variable showing path from which package is loaded -sys.path is a list where moduled will be searched -a package is implemented by creating __init__...