- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.py
More file actions
Latest commit
33 lines (26 loc) · 831 Bytes
/
Copy pathfile.py
File metadata and controls
33 lines (26 loc) · 831 Bytes
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
#### DOSYA OKUMA ####
# Eğer dosya yoksa
try:
file=open("info.txt", "r")
exceptFileNotFoundError:
print("Dosya Bulunamadı")
# file üzerinde satır satır gezme
foriinfile:
print(i)
file.close()
# Tüm satırları listeye alma
liste=file.readlines()
file.close()
# Dosya okumanın kolay yolu open ve close fonksiyonlarını kullanamıza gerek kalmaz.
# İlk 4 karakterin okuma, boş bırakılırsa tamamını okur.
withopen(example1, "r") asfile1:
print(file1.read(4))
#### DOSYA YAZMA ####
# Satır yazma
withopen('/resources/data/Example2.txt', 'w') aswritefile:
writefile.write("This is line A")
#### DOSYA KOPYALAMA ####
withopen('Example2.txt','r') asreadfile:
withopen('Example3.txt','w') aswritefile:
forlineinreadfile:
writefile.write(line)