Skip to content

rajputakhil/package

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Program = Modules + Packages

  1. This is a step-by-step demonstration to divide Python code base into clean, efficient modules using Python packages.
  2. Additionally, you'll learn to import and use your own packages, thus building your own Python program.

Instructions to execute a Python package having two funcitons

  1. Create a directory named 'package'.

  2. Create an empty file named __int__.py (this will tell the interpreter that its a package)

  3. Create a file named 'fn1.py' with a function in it.

def functionOne():
    print("This is Function One")
    return
  1. Create another file named 'fn2.py' with a different function in it.
def functionTwo():
    print("This is Function Two")
    return
  1. Create a file named 'test.py' with a set of python code to execute fn1 and fn2 functions.
import fn1, fn2
fn1.functionOne()
fn2.functionTwo()
  1. Open Terminal and log into the folder 'package' and type in the follwoing command to execute test.py file:
$ cd package
$ chmod a+x test.py
$ python3 test.py
  1. The program test.py will get executed, generating the following output:
This is Function One
This is Function Two

Note: The program will run for both Python 2 as well as Python 3 versions.

About

How to build a Python Program?

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages