Using Python to Interact with the Operating System Week2 Solution

Using Python to Interact with the Operating System WEEK 2 Qwiklabs Assessment Coursera  by Google. Welcome to Using Python to Interact with the Operating System. You’re joining thousands of learners currently enrolled in the course. This course is a part of Google IT Automation with Python Professional Certificate. Qwiklabs Assessment : “Handling Files”

I’m excited to have you on my channel and look forward to your contributions to the learning community. By the end of this course:

  1. you’ll be able to manipulate files and processes on your computer’s operating system. You’ll also have learned about regular expressions a very powerful tool for processing text files
  2. you’ll get practice using the Linux command line on a virtual machine.

And, this might feel like a stretch right now, but you’ll also write a program that processes a bunch of errors in an actual log file and then generates a summary file. That’s a super useful skill for IT Specialists to know.

-:Skills you will learn:-

  •  Setting up your Development Environment
  • Regular Expression (REGEX) 
  • Testing in Python 
  • Automating System Administration Tasks with Python
  • Bash Scripting

~Course Link: https://www.coursera.org/learn/python-operating-system

Qwiklabs Assessment : “Handling Files”

Codes:-

				
					#!/usr/bin/env python3
import csv
def read_employees(csv_file_location):
   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
employee_list = read_employees('/home/student-00-807b64735878/data/employees.csv')
print(employee_list)
				
			
				
					#!/usr/bin/env python3
import csv
def read_employees(csv_file_location):
  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
employee_list = read_employees('/home/student-00-807b64735878/data/employees.csv')
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
dictionary = process_data(employee_list)
print(dictionary)
				
			
				
					#!/usr/bin/env python3
import csv
def read_employees(csv_file_location):
  csv.register_dialect('empDialect', skipinitialspace=True, strict=True)
  employee_file = csv.DictReader(open(csv_file_location), dialect = 'empDial$
  employee_list = []
  for data in employee_file:
     employee_list.append(data)
  return employee_list
employee_list = read_employees('/home/student-00-807b64735878/data/employees$
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_na$
    return department_data
dictionary = process_data(employee_list)
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()
write_report(dictionary, '/home/student-00-807b64735878/data/report.txt')
				
			

Leave a Reply

Your email address will not be published. Required fields are marked *