Skip to content

Commit eacbaa6

Browse files
author
mustafa
committed
setattrgetattr ornek1
1 parent bb2537d commit eacbaa6

File tree

3 files changed

+44
-16
lines changed

3 files changed

+44
-16
lines changed

getattr_ornek.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class DataModel():
2+
veriler = {"ihsan": "erdem", "betul": "tezel", "derya": "karaarslan"}
3+
4+
def veriyi_modifiyeet(self, veri):
5+
if type(veri) == str:
6+
return veri.upper()
7+
else:
8+
return veri
9+
10+
def __setattr__(self, key, value):
11+
yeni_value = self.veriyi_modifiyeet(value)
12+
self.veriler.update({key:yeni_value})
13+
#return object.__setattr__(self, key, yeni_value)
14+
15+
def __getattr__(self, item):
16+
print(item)
17+
if item != "veriler":
18+
if self.veriler.get(item) is not None:
19+
return self.veriler.get(item)
20+
21+
return object.__getattribute__(self, item)
22+
23+
24+
class DataTable(DataModel):
25+
pass
26+
27+
28+
data = DataTable()
29+
data.mustafa = "deneme"
30+
print(data.veriler)
31+
print(data.ihsan)

getsetattr_ornek2.py

Whitespace-only changes.

keepasx.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def __init__(self, file_name):
1414
1 - Yeni parola oluştur
1515
2 - Parolaları listele
1616
3 - Parola ara
17-
""",is_numeric=True)
17+
""", is_numeric=True)
1818
if menu == 1:
1919
self.register_new_pass()
2020
elif menu == 2:
@@ -25,11 +25,8 @@ def __init__(self, file_name):
2525
else:
2626
print('Hatalı Girdi')
2727

28-
29-
30-
def input_control_error(self,text,is_numeric=False):
31-
input_error = True
32-
while input_error:
28+
def input_control_error(self, text, is_numeric=False):
29+
while True:
3330
input_data = input(text)
3431
if input_data.strip() != "":
3532
if is_numeric:
@@ -42,8 +39,6 @@ def input_control_error(self,text,is_numeric=False):
4239
else:
4340
print('Geçersiz girdi')
4441

45-
46-
4742
def register_new_pass(self):
4843
"""
4944
Kullanıcıdan kullanıcı adı , açıklama ve parola ister
@@ -53,19 +48,20 @@ def register_new_pass(self):
5348
username = self.input_control_error("Lütfen Kullanıcı adı giriniz :")
5449
password = input("Lütfen parolanızı giriniz:")
5550
if password.strip() == "":
56-
password_length = self.input_control_error('Lütfen parola uzunluğu giriniz',is_numeric=True)
51+
password_length = self.input_control_error('Lütfen parola uzunluğu giriniz', is_numeric=True)
5752
password = self.generate_pass(password_length)
5853
aciklama = self.input_control_error("Lütfen açıklama giriniz :")
5954

60-
61-
62-
self.mypasslist.append({"username":username,"password":password,"description":aciklama})
55+
self.mypasslist.append({"username": username, "password": password, "description": aciklama})
6356
self.save()
6457

65-
def edit(self):
58+
def edit(self,text,is_numeric=False):
6659
"""
6760
verilen index'te olan veriyi değiştirir
6861
"""
62+
print('Edit çağrıldı')
63+
64+
6965

7066
def load(self):
7167
"""
@@ -88,7 +84,7 @@ def list(self):
8884
for passlist in self.mypasslist:
8985
print(list(passlist.values()))
9086

91-
def search(self,keyw):
87+
def search(self, keyw):
9288
"""
9389
vericeğimiz parametreye göre parolalar arasında arama yapacak
9490
"""
@@ -102,8 +98,9 @@ def save(self):
10298
"""
10399
data = ""
104100
for i in self.mypasslist:
105-
data += "{username}@ayrac@{passw}@ayrac@{desc}\n".format(username=i.get('username'),passw=i.get('password'),desc=i.get('description'))
106-
with open(self.file_name,"w") as file:
101+
data += "{username}@ayrac@{passw}@ayrac@{desc}\n".format(username=i.get('username'),
102+
passw=i.get('password'), desc=i.get('description'))
103+
with open(self.file_name, "w") as file:
107104
file.write(data)
108105

109106
def generate_pass(self, length):

0 commit comments

Comments
 (0)