1# __init__.py
2# you can comment here about your package.
3# you can also add external libraries to your package.
4# for example:
5import numpy
6import pandas
7
8# you can also add your package information in this file.
9__version__ = '2.1.1'
10__author__ = 'Depressed Dingo'
11
12# __all__ make others able to access to this datas by importing our package.
13__all__ = ['numpy', 'pandas', '__version__', '__author__']
14
15
16# -----------------------------------------
17# main.py
18# example of using this.
19
20from test_package import *
21# or
22from test_package import numpy
23
24print(__auther__) # --> Depressed Dingo
1class Person:
2 def __init__(self, name, age):
3 self.name = name
4 self.age = age
5
6p1 = Person("John", 36) // Object definition
7
8print(p1.name)
9print(p1.age)
1#!/usr/bin/python
2
3class Employee:
4 'Common base class for all employees'
5 empCount = 0
6
7 def __init__(self, name, salary):
8 self.name = name
9 self.salary = salary
10 Employee.empCount += 1
11
12 def displayCount(self):
13 print "Total Employee %d" % Employee.empCount
14
15 def displayEmployee(self):
16 print "Name : ", self.name, ", Salary: ", self.salary
17
18"This would create first object of Employee class"
19emp1 = Employee("Zara", 2000)
20"This would create second object of Employee class"
21emp2 = Employee("Manni", 5000)
22emp1.displayEmployee()
23emp2.displayEmployee()
24print "Total Employee %d" % Employee.empCount
1class A(object):
2 def __init__(self):
3 self.x = 'Hello'
4
5 def method_a(self, foo):
6 print self.x + ' ' + foo
7