-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFinal_Test.py
44 lines (39 loc) · 1.75 KB
/
Final_Test.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
"""The openpyxl library has been downloaded for its fonctionalities to be usable in this code"""
"""Importing foction workbook from openpyxl library"""
from openpyxl.workbook import Workbook
"""Importing foction load_workbook from openpyxl library that permits to access the excel sheet"""
from openpyxl import load_workbook
"""Importing csv library which permits to carry out operations on csv files"""
import csv
"""using the load_workbook to access the excel sheet which is assigned to the variable wb"""
wb = load_workbook('employeedata.xlsx')
"""Using the active fonction to use the sheet containing our data"""
ws = wb.active
"""for loop that permits to move accross the columns of the row to be edited"""
for row in ws.rows:
row[3].value
Abd = row[3].value
"""The replace fonction searches the string to be replaced and replaces it """
row[3].value = Abd.replace("@helpinghands.cm","handsinhands.org")
"""saves the final version into Output.xlsx"""
wb.save('Output.xlsx')
"""setting up an output file"""
outfile = open('CSVOutput.csv ', 'w')
"""setting up the input file"""
with open('employeedata.csv', 'r') as csv_file:
"""Using the reader fonction to read the csv"""
csv_reader = csv.reader(csv_file)
header = next(csv_reader)
"""iterating through the csv"""
for row in csv_reader:
NAME = row[0]
L_NAME = row[1]
CONTACT =row[2]
EMAIL = row[3]
ADDRESS =row[4]
"""Using an if statement to edit the csv"""
if 'helpinghands.cm' in EMAIL:
new_email=(EMAIL).replace('helpinghands.cm','handsinhands.org')
line = "{},{},{},{}\n".format(NAME,L_NAME, CONTACT,new_email, ADDRESS)
outfile.write(line)
outfile.close()