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.

Where to get data-sets to practice data science?

Data is the new science. Big data holds the answers. - Pat Gelsinger, CEO 1. Programmable Web  Description:   This is a site where you can obtain API's to extract data from some of the biggest sites on the internet. Link address:   API Directory Examples : Google maps API, Instagram API, Twitter API etc. 2. Postman API Development Description:   An online tool that you can use to access millions of APIs on the internet. You can also develop your own API if you happen to own a site. Link address:   API TOOL  Examples : Paypal API, Adobe API, Coursera API etc. 3. Facebook graph Description:   An online tool that you can use to access data about Facebook pages. Link address:   API  Examples : graph.facebook.com/youtube  - Access page data, e.g likes, number of posts etc. 4. APIGEE Description:   An online GUI tool that lets your extract and send data to various web platforms Link ad...

Setting up Django for Heroku Deployment

In this tutorial , we are going to show how to deploy your Django 2.0 web application on the Heroku platform. This tutorial assumes that you are familiar with the django framework, git and the Linux command line. In addition if you haven't done so already, register an account with Heroku . Django dependencies SETUP Install virtual env on your linux machine $ sudo apt-get install virtual env A virtual environment such as (virtual env) allows you to run your application in an isolated environment from your local machine. This is useful if you have multiple applications on your computer that use different versions of certain software packages( python 2.7 for application 1 and python 3.6.4 for application 2) 2. Navigate to your working directory to Create and Activate the virtual environment $ virtualenv  .vEnv $ .  .vEnv/bin/activate Take care not to omit the dots! 3. Install django 2.0 using pip ( Note: You need to have python3 and pip pre-installed...