Skip to content

Commit 6f4fbc1

Browse files
author
mustafa
committed
json örnekleri 2 yapıldı.
keepassX üzerinde json formatında yazma örneği eklendi.
1 parent 2485c82 commit 6f4fbc1

File tree

3 files changed

+49
-17
lines changed

3 files changed

+49
-17
lines changed

csv_okuma.py

Whitespace-only changes.

json_loads.py

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,39 @@
11
import json
22

3-
data = {"polisiye": ["Sherlock", "Behzat Ç."], "fantastik": ["Silmarillion",
4-
"Cüce Derinlikleri Ejderhaları",
5-
"İkizlerin Savaşı",
6-
"İkizlerin Sınavı",
7-
"Otostopçunun ..."]}
3+
data = {"polisiye": ["Sherlock", "Behzat Ç."],
4+
"fantastik": ["Silmarillion",
5+
"Cüce Derinlikleri Ejderhaları",
6+
"İkizlerin Savaşı",
7+
"İkizlerin Sınavı",
8+
"Otostopçunun ...",
9+
"Harry Potter"],
10+
"klasikler": ["Beyaz Zambaklar Ülkesi",
11+
"Sefiller",
12+
"Yeraltından Notlar"]}
813

914

15+
try:
16+
with open("kitaplar.txt", "w") as dosya:
17+
json.dump(data, dosya)
18+
except Exception(IOError) as hata:
19+
print(hata)
1020

11-
with open("kitaplar.txt","w") as dosya:
12-
json.dump(data,dosya)
1321

14-
with open("kitaplar.txt") as dosya:
15-
data = json.load(dosya)
16-
print(data)
22+
try:
23+
with open("kitaplar.txt") as dosya:
24+
data = json.load(dosya)
25+
print(data)
26+
print(type(data))
27+
print(data.values())
28+
except Exception(IOError) as hata:
29+
print(hata)
30+
31+
# temp_liste = ["1","2","3","4","5"]
32+
33+
# try:
34+
# with open("yeni_kitaplar.txt", "w") as dosya:
35+
# for i in temp_liste:
36+
# dosya.write(i)
37+
# except IOError as hata:
38+
# print(hata)
39+

keepasx.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import string as sg
22
import random
3+
import json
34

45

56
class Keepasx():
@@ -61,21 +62,24 @@ def edit(self,text,is_numeric=False):
6162
"""
6263
print('Edit çağrıldı')
6364

64-
65+
6566

6667
def load(self):
6768
"""
6869
verdiğimiz dosya isminine bakarak okuma yapacak
6970
"""
7071
with open(self.file_name) as file:
72+
print(file.read())
7173
file_data = file.read().strip().split("\n")
7274
for veriler in file_data:
7375
veri_yigini = veriler.split("@ayrac@")
7476
self.mypasslist.append(
7577
{"username": veri_yigini[0],
7678
"password": veri_yigini[1],
7779
"description": veri_yigini[2]})
78-
80+
# with open(self.file_name) as file:
81+
# file_data = json.load(file)
82+
# print(file_data)
7983
def list(self):
8084
"""
8185
parolalarımızı listeleyecek
@@ -96,12 +100,16 @@ def save(self):
96100
"""
97101
dosyaya kayit yapacak
98102
"""
99-
data = ""
100-
for i in self.mypasslist:
101-
data += "{username}@ayrac@{passw}@ayrac@{desc}\n".format(username=i.get('username'),
102-
passw=i.get('password'), desc=i.get('description'))
103+
# data = ""
104+
# for i in self.mypasslist:
105+
# data += "{username}@ayrac@{passw}@ayrac@{desc}\n".format(username=i.get('username'),
106+
# passw=i.get('password'), desc=i.get('description'))
107+
# with open(self.file_name, "w") as file:
108+
# file.write(data)
109+
110+
103111
with open(self.file_name, "w") as file:
104-
file.write(data)
112+
json.dump(self.mypasslist, file)
105113

106114
def generate_pass(self, length):
107115
string_data = sg.printable
@@ -110,3 +118,4 @@ def generate_pass(self, length):
110118

111119
kep = Keepasx("passfile.txt")
112120
print(kep.generate_pass(10))
121+
print(kep.load())

0 commit comments

Comments
 (0)