Class 4 Lab 10 ‐ Opening & Analyzing Files - Justin-Boyd/Python-Class GitHub Wiki

Task 1

  • Click on File from the top menu and select Open File. Verify the displayed folder is /home/student/workspace, select main.py, and click Open.

Task 2

def main():
    log_file_path = input("Enter log file path: ")
    log_file = open(log_file_path, "r")

Task 3

    output_file_path = input("Enter name of result file: ")
    with open(output_file_path, "w") as f:
        f.write("")
    output_file = open(output_file_path, "a")

Task 4

    for line in log_file.readlines():
        print(line)

Task 5

        if ("regular" in line or "root" in line) and "Linux" in line:
            print(line)

Task 6

            output_file.write(line)

Task 7

    try:
        main()
        print("file created successfully ")
    except Exception as e:
        print(e)