-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCours 14.py
More file actions
58 lines (44 loc) · 1.45 KB
/
Copy pathCours 14.py
File metadata and controls
58 lines (44 loc) · 1.45 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
import os
os.chdir("OneDrive\Documents\ESILV\S5\Python")
file = open(r"names.txt", "r")
for name in file:
name = name.strip()
print("Hello {} !".format(name))
file = open(r"names.txt", "r")
for name in file:
if "a" in name:
name = name.strip()
print("Hello {} !".format(name))
file = open(r"names.txt", "r") #reading
file = open(r"names.txt", "w") #writing
file = open(r"names.txt", "a") #appending
file = open(r"names.txt", "r+") #reading and writing
print(file.name)
print(file.mode)
file.close()
with open(r"names.txt", "r") as file:
print(file.read())
with open(r"names.txt", "r") as file:
print(file.readlines())
with open(r"names.txt", "r") as file:
print(file.readline())
print(file.readline())
print(file.readline())
print(file.readline())
print(file.readline())
with open(r"test.txt", "w") as file:
file.write("Test")
with open(r"test.txt", "r") as file:
print(file.read())
with open(r"test.txt", "w") as file:
file.write("Hello World")
file.seek(0)
file.write("R")
with open(r"names.txt", "r") as file_r:
with open(r"test.txt", "w") as file_w:
for line in file_r:
file_w.write(line)
with open(r"image.jpg", "rb") as file_r:
with open(r"image_copy.jpg", "wb") as file_w:
for line in file_r:
file_w.write(line)