You are on page 1of 1

os.path.

getmtime()
x=datetime.datetime.fromtimestamp(timestamp)
return ("{}".format(x.strftime("%Y-%m-%d")))
relative_parent = os.path.join(os.getcwd(), os.pardir)
return os.path.abspath(relative_parent)
if os.path.isdir(directory) == False:
os.mkdir(directory)
os.listdir()
os.path.getsize(filename)
csv.reader(f)
writer =csv.writer(f)
writer.writerows(mat)
reader = csv.DictReader(f)//for
with open(filename)as f:

with open(filename) as f:
# Read the rows of the file into a dictionary
f = csv.DictReader(f)
# Process each item of the dictionary
for row in f:
return_string += "a {} {} is {}\n".format(row["color"], row["name"],
row["type"])
return return_string

#!/usr/bin/env python3
import csv
def read_employees(csv_file_location):
with open(csv_file_location) as f:
csv.register_dialect('empDialect', skipinitialspace=True,
strict=True)
employee_file = csv.DictReader(open(csv_file_location), dialect =
'empDialect')
employee_list = []
for data in employee_file:
employee_list.append(data)
return employee_list
def process_data(employee_list):
department_list = []
for employee_data in employee_list:
department_list.append(employee_data['Department'])
department_data = {}
for department_name in set(department_list):
department_data[department_name] =
department_list.count(department_name)
return department_data
def write_report(dictionary, report_file):
with open(report_file, "w+") as f:
for k in sorted(dictionary):
f.write(str(k)+':'+str(dictionary[k])+'\n')
f.close()
employee_list = read_employees('/home/student-00-d48d5c6af8ef/data/employees.csv')
dictionary = process_data(employee_list)
write_report(dictionary, '/home/student-00-d48d5c6af8ef/test_report.txt')

You might also like