-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession14.py
More file actions
56 lines (38 loc) · 1.13 KB
/
session14.py
File metadata and controls
56 lines (38 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# session important in view of interview
class Point:
def __init__(self, x=0, y=0):
self.x = x
self.y = y
# If u wish to have more different ways other than __init
# We can create methods of our own choice
@classmethod # Known as Decorator
def createPoint(cls, data): # cls ->reference variable to the class
points = data.split(",")
# cls makes init to work
refToObj = cls(int(points[0]), int(points[1]))
return refToObj # hashcode of object created returning to p3
def showPoint(self):
print("Point is:", self.x, self.y)
@staticmethod # Decorator
def greet(name):
print("Hello ", name)
@staticmethod
def check(i1, i2):
return i1>i2
p1 = Point()
p2 = Point(10, 20)
p1.showPoint()
p2.showPoint()
file = open("points.txt.py", "r")
data = file.readline()
print(data)
""""
points = data.split(",")
print(points[0], points[1])
print(type(points[0]), type(points[1]))
p3 = Point(int(points[0]), int(points[1]))
"""
p3 = Point.createPoint(data)
p3.showPoint()
print("Greater is :",Point.check(p3.x, p3.y))
Point.greet("Ayushi")