-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchange_class.py
More file actions
40 lines (28 loc) · 856 Bytes
/
Copy pathchange_class.py
File metadata and controls
40 lines (28 loc) · 856 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
34
35
36
37
38
39
40
import os
def change_class(path,num):
f = open(path,'r')
lines = f.readlines()
s = ''
if len(lines)!=0:
for line in lines:
if line[1].isdigit():
line=str(num)+line[2:]
else:
line=str(num)+line[1:]
print(line)
s+=line
f.close()
# Открываем файл для записи
save_changes = open(path, 'w')
# Сохраняем список строк
save_changes.writelines(s)
# Закрываем файл
save_changes.close()
def change_class_inside(path,num):
for filename in os.listdir(path):
f = os.path.join(path, filename)
if os.path.isfile(f):
if filename.endswith('.txt'):
change_class(f,num)
if __name__=='__main__':
change_class_inside('birds',0)