-
Notifications
You must be signed in to change notification settings - Fork 0
/
19-python-files.py
66 lines (57 loc) · 1.04 KB
/
19-python-files.py
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
from io import open
text = "First line \nSecond line"
file = open('file_test.txt', 'w')
file.write(text)
file.close()
del file
file = open('file_test.txt', 'r')
text = file.read()
file.close()
print(text)
del file
file = open('file_test.txt', 'r')
lines = file.readlines()
file.close()
del file
print(lines)
print(lines[0])
print(lines[-1])
file = open('file_test.txt', 'a')
file.write('\nFour line')
file.close()
del file
file = open('file_test.txt', 'r')
line = file.readline()
print(line)
line = file.readline()
print(line)
line = file.readline()
print(line)
line = file.readline()
print(line)
file.close()
del file
with open('file_test.txt', 'r') as file:
for line in file:
print(line)
file = open('file_test.txt', 'r')
file.seek(10)
file.read()
file.read()
file.seek(0)
file.read()
file.seek(0)
file.read(5)
file.close()
del file
file = open('file_test.txt', 'r')
file.seek(0)
text = file.read()
file.seek(len(text)/2)
file.read()
file.close()
del file
file = open('file_test.txt', 'r+')
file.write('New Line\n')
file.close()
del file