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 Rectangle:
2 def __init__(self, length, breadth, unit_cost=0):
3 self.length = length
4 self.breadth = breadth
5 self.unit_cost = unit_cost
6 def get_area(self):
7 return self.length * self.breadth
8 def calculate_cost(self):
9 area = self.get_area()
10 return area * self.unit_cost
11# breadth = 120 units, length = 160 units, 1 sq unit cost = Rs 2000
12r = Rectangle(160, 120, 2000)
13print("Area of Rectangle: %s sq units" % (r.get_area()))
1class A(object):
2 def __init__(self):
3 self.x = 'Hello'
4
5 def method_a(self, foo):
6 print self.x + ' ' + foo
7
1class MyClass(object):
2 i = 123
3 def __init__(self):
4 self.i = 345
5
6a = MyClass()
7print(a.i)
8print(MyClass.i)
9
10# Output:
11# 345
12# 123