-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise_22.py
More file actions
27 lines (21 loc) · 891 Bytes
/
exercise_22.py
File metadata and controls
27 lines (21 loc) · 891 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
from csv import writer, reader
class passwd_to_csv:
def __init__(self, file_input: str, file_output: str):
self.file_input = file_input
self.file_output = file_output
self.file_content_in_rows = self.read_file()
self.write_file()
def read_file(self):
file_content_in_rows = []
with open(self.file_input, 'r') as r_file:
content = reader(r_file, delimiter=':')
for i in content:
if not "".join(i).startswith('#'):
file_content_in_rows.append([i[0], i[2]])
return file_content_in_rows
def write_file(self):
with open(self.file_output, 'w', newline='\n') as w_file:
writer_f = writer(w_file, delimiter='\t')
for i in self.file_content_in_rows:
writer_f.writerow(i)
passwd_to_csv("exercise_22.csv", "output.csv")