-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask_1.py
More file actions
33 lines (26 loc) · 1.08 KB
/
task_1.py
File metadata and controls
33 lines (26 loc) · 1.08 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
import os
import csv
def write_info(name_csv: str, rating: int) -> None:
"""
the function enters the full path, relative path and review rating
"""
full_path = os.path.abspath('dataset')
name_review = os.listdir(os.path.join(full_path, str(rating)))
relative_path = os.path.relpath('dataset')
with open(name_csv, 'a', newline='') as csv_file:
writer = csv.writer(csv_file, delimiter=",", lineterminator='\r')
for name in name_review:
writer.writerow([os.path.join(full_path, str(rating), name), os.path.join(relative_path, str(rating), name), rating])
def create_csv_file(name_csv: str) -> None:
"""
the function creates a csv file and enters the name of the columns
"""
with open(name_csv, 'w') as csv_file:
writer = csv.writer(csv_file, delimiter=",", lineterminator='\r')
writer.writerow(["absolute_path", "relative_path", "rating"])
def main() -> None:
create_csv_file('annotation1.csv')
for i in range(1, 6):
write_info('annotation1.csv', i)
if __name__ == "__main__":
main()