8000 python packages · dsabhrawal/python-examples@e51de65 · GitHub
[go: up one dir, main page]

Skip to content

Commit e51de65

Browse files
Deepak SabhrawalDeepak Sabhrawal
authored andcommitted
python packages
1 parent 8d0d6ab commit e51de65

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

ObjectOrientedPython/BasicClass.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
class Employee:
1515
''' This is the version 1.0 of Employee class''' #doc string
1616
#Defining constructor of class Employee
17-
#self refers to the current object (same like this in java)
17+
#self refers to the current object (same like this in java programming)
1818
#any variable defined with self is an instance variable in python
1919
def __init__(self):
2020
super().__init__()
@@ -50,6 +50,6 @@ def display(self):
5050
#Employee Salary: 100000
5151

5252
#Important Notes:
53-
#self is not a keyword or reserved word is python
53+
#self is not a keyword or reserved word in python
5454
#we can use any name instead of self like this
5555
#The first parameter paased to any instance method is pointing to the current object

ObjectOrientedPython/test_package.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#Here we will import calculator module from the custom package
2+
3+
#If you see no myfirstpackage module found error make sure your project directory is
4+
#on the class path
5+
#hit this on command prompt with proper path of your project directory
6+
#export PYTHONPATH="${PYTHONPATH}:/path/to/your/project"
7+
8+
from myfirstpackage import calculator as calc
9+
10+
print(calc.sum(2,3))
11+
12+
print(calc.mul(2,3))
13+

myfirstpackage/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#every package folder would have __init__.py file to declare it as a package
2+
print('Initializing myfirstpackage!')

myfirstpackage/calculator.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#This module will have calculator functionality.
2+
3+
def sum(x,y):
4+
return x+y
5+
6+
7+
def sub(x,y):
8+
return x-y
9+
10+
11+
def mul(x,y):
12+
return x*y
13+
14+
15+
def div(x,y):
16+
return x/y

0 commit comments

Comments
 (0)
0