-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path64. Read external file Open and With.py
More file actions
58 lines (33 loc) · 1.18 KB
/
64. Read external file Open and With.py
File metadata and controls
58 lines (33 loc) · 1.18 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
55
56
57
58
## Tutorial membaca file eksternal
print("\n","="*3,"Membaca File Txt","="*3,"\n")
file =open("data64.txt",mode="r")
print(f"Status read : {file.readable()}")
print(f"Status write : {file.writable()}")
## Baca sluruh file
print(file.read())
# ## baca per baris
# print(file.readline(), end="") # baca baris pertama
# print(file.readline(), end="") # baca baris kedua
# ## Baca semua baris
# print(file.readlines())
print(f"Apakah file sudah di close : {file.closed}")
file.close()
print(f"Apakah file sudah di close : {file.closed}")
## salah satu teknik membuka file di python
print("\n","="*3,"Membaca File Txt dg with","="*3,"\n")
with open("data64.txt", mode="r") as file:
content = file.readline()
print(content,end="")
print(f"Apakah file sudah di close : {file.closed}")
if file.closed == True:
bukaTutup = "Sudah"
else:
bukaTutup = "Belum"
print(f"Lagi ya!! Apakah file sudah di close : {bukaTutup}")
print()
# bukaTutup = ""
if file.closed == True:
bukaTutup = "Sudah"
else:
bukaTutup = "Belum"
print(f"Apakah file sudah di close : {bukaTutup}\n")