-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileWriteOpenReadClose.py
More file actions
141 lines (99 loc) · 2.54 KB
/
FileWriteOpenReadClose.py
File metadata and controls
141 lines (99 loc) · 2.54 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
print(''' To only read an external file
works_file=open("works.txt","r")
''')
works_file=open("works.txt","r")
print(''' To only read and write an external fil
works_file=open("works.txt","r+")
''')
works_file=open("works.txt","r+")
print(''' To only write an external fil
works_file=open("works.txt","w")
''')
works_file=open("works.txt","w")
print(''' To only write at the end or append at an external fil
works_file=open("works.txt","a")
''')
works_file=open("works.txt","a")
print('''
TO find out if the file is readable or not
print(works_file.readable())
''')
print(works_file.readable())
print(''' TO read the whole ,file
print(works_file.read())
''')
print(works_file.read())
print(''' to read only the first line
print(works_file.readline())
''')
print(works_file.readline())
print(''' to read only the first three line together
print(works_file.readline())
print(works_file.readline())
print(works_file.readline())
''')
print(works_file.readline())
print(works_file.readline())
print(works_file.readline())
print(''' to read all line together in a list
print(works_file.readlines())
''')
print(works_file.readlines())
print(''' to read the 3rd or indexed 2nd line in a list
print(works_file.readlines()[2])
''')
print(works_file.readlines()[2])
print(''' TO close the file
works_file.close()
''')
works_file.close()
print('''
''')
print('''
''')
print('''
''')
print('''
To append a file
works_file=open("works.txt","a")
''')
works_file=open("works.txt","a")
print('''
TO write in the file
works_file.write(" \n read books 10:00")
''')
works_file.write(" \n read books 10:00")
print('''
To write a file in or overwrite the/ a file
create a new file named works222.txt
works_file=open("works222.txt","w")
''')
works_file=open("works222.txt","w")
print('''
To write a file in or overwrite the/ a file
create a new file named works333.txt
works_file=open("works333.txt","w")
''')
works_file=open("works333.txt","w")
print('''
TO write in the file
works_file.write(" \n read books 10:00")
''')
works_file.write(" \n read books 10:00")
print('''
To write a file in or overwrite the/ a file
create a new file named works333.txt
works_file=open("works444.html","w")
''')
works_file=open("works444.html","w")
print('''
TO write in the file
works_file.write(" <p> This is HTML <p>")
''')
works_file.write(" <p> This is HTML <p> ")
print(''' TO close the file
works_file.close()
''')
works_file.close()
print('''
''')