Skip to main content

Python packages

Package Module Structure in Python Programming


A python package is a collection of python modules. These modules are python scripts with *.py file extension. Typically, these scripts will contain python functions, classes, custom data types etc.


Looking at the figure above, the Game package consist of an _init_.py file together with 3 other sub-packages Sound, Image and Level respectively.
The _init_.py file must be included inside a directory for it to be considered a python package.In addition, the directory must be defined inside sys.path.

Example usage:

1. import Game.Level.Start
  • Suppose the start.py module consists of a function called mince()
  • Inside your python application, you would need to call it as follows
2. Game.Level.Start.mince(<input_params>)
  • Alternatively, you can reference it as follows
3. from Game. Level import Start     // recommended approach
4. Start.mince(<input_params>)
  • A less common method is calling the function as if it was defined inside your current script
5. from Game.Level.Start import mince       //not recommended 
6. mince(<input_params>)

Comments

Popular posts from this blog

PIP vs CONDA

Both are ' package managers' that can be used to install python packages such as numpy, matplotlib, seaborn etc. Although conda is more of an environmental manager  than it is a package manger. A package manager is simply a software tool used to automate the process of installing , updating  and removal of software packages(libraries). Conda PIP Can install non-python libraries Can only install python libraries Cross platform package manager Python package manager Install python packages in conda-environment Install python packages in any environment Leave any other disparities in the comments section below,so they can be added to the list.

Too much abstraction

Abstraction refers to the method of 'hiding' implementation details in the process of software development. This technique is useful to prevent code duplication in a computer application. Usually, this is achieved by the use of libraries, packages or modules contained in the programming language core library or from external sources. So what is the issue here....... Too much of anything is umm... bad for you! Most new programmers grow up with little information concerning how most libraries work in the background Cloud computing eliminates the need for  hardware set up and low level machine configurations Modern programmers are mostly concerned with integrating several "black boxes" to create innovative and disruptive solutions - GREAT! "Essentially, we're progressing into an age where no one knows how to operate a manual transmission vehicles" - SAD! Potential issues What happens when the background code in the abstraction "...