0% found this document useful (0 votes)
39 views1 page

Py

Uploaded by

Salmen Allouch
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views1 page

Py

Uploaded by

Salmen Allouch
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 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