-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaula130.py
39 lines (31 loc) · 946 Bytes
/
aula130.py
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
# method vs @classmethod vs @staticmethod
# method - self, método de instância
# @classmethod - cls, método de classe
# @staticmethod - método estático (❌self, ❌cls)
class Connection:
def __init__(self, host='localhost'):
self.host = host
self.user = None
self.password = None
def set_user(self, user):
self.user = user
def set_password(self, password):
self.password = password
@classmethod
def create_with_auth(cls, user, password):
connection = cls()
connection.user = user
connection.password = password
return connection
@staticmethod
def log(msg):
print('LOG:', msg)
def connection_log(msg):
print('LOG:', msg)
# c1 = Connection()
c1 = Connection.create_with_auth('luiz', '1234')
# c1.set_user('luiz')
# c1.set_password('123')
print(Connection.log('Essa é a mensagem de log'))
print(c1.user)
print(c1.password)