Skip to main content

Python package

Python package is organization of code directory. that can be contains various modules and configuration files. in simple word that is an directory structures of codes file. this directory is much contains of file. look at this example.

python directory example

In this structure App is main mackage and (Setting,Operation,Db) is sub module.

App Db Operation Settings

In this example we can access any module of this package outside of App folder. suppose we are use the module of App>>Db>> file. first see the

def deleteData():
  print("Delete Data Function")

This file are contain one function deleteData(). so how to use this file function outside the app folder?. that is very simple. help of package directory we can access this file function.


for example suppose is exist outside app folder. and this file imported package of (App>>Dd>>delete) module.
import App.Db.delete
Delete Data Function is used to access module of directory. so it is very important to define this file. this file may be empty but that are used to create package.

for example if we are delete the file in App folder (app root then python3 is display an error. see this example.

Traceback (most recent call last):
  File "", line 1, in <module>
    import App.Db.delete
ImportError: bad magic number in 'App': b'\x03\xf3\r\n'


Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment