Python Packages are nothing but a namespace or a hierarchical file directory structure that may contain multiple python script,modules or sub-packages or Packages. They are nothing but a simple directories, but it contains a file called __init__.py .This __init__.py indicate that the folder or directory is the Python Packages.you can keep __init__.py file empty or may insert some code.
To Create Python Packages fallow the below steps:
- Create “Hello” directory/folder in Desktop [you can name it whatever you want ,create it in any folder/directory]
- Now create 3 python file as shown in below images named as example.py , example2.py , __init__.py
- example.py contain a simple class based example
- example2.py contains a simple function
- __init__.py contain import statement,that makes code available that define in example.py and example2.py
- Now create example1.py script outsite the “hello” directory [i.e in Desktop] and write code as given in image
- We have created a package called “hello” and used it in example1.py script,now run the code in terminal as given in image,you will get the fallowing output .
For more details you can visit python official website https://docs.python.org/2/tutorial/modules.html#packages
Hope guys you will understand the concept of Python Packages clearly.Try to implement it with more code,and if you find any difficulty, feel free to drop a comment on this post.