0

so I need to get the 3 commented codes to work but nothing I do seems to work any tips/tricks work be great thanks.

This file prints information about a file

import os.path


def main():
    filename = "students.txt"
    abs_file_path = os.path.abspath(filename)  # returns absolute path for the given file
    dir_name = os.path.dirname(abs_file_path)  # returns filename without directory in front of it
    print()
    print()
    print("Absolute Path : ", abs_file_path)
    print("Directory : ", dir_name)  # returns directory given file is in
    print("Base Name : ", os.path.basename(abs_file_path))  # returns filename without directory in front of it

    #print("File Size : ", os.path.getsize(filename))  # returns the size of the given file in bytes
    # print("Is A File? : ", os.path.isfile(filename))  # returns 'True' if the given file exists
    # print("Is A Directory? : ", os.path.isdir(filename))  # returns 'True' if the given directory exists


if __name__ == '__main__':
    main()

enter image description here

1 Answers1

0

A quick solution to your question is to change the following line

  filename = "students.txt"

to

 filename = r"students.txt"

or

 filename = R"students.txt"

the r or R implies raw string read

Additionally, please read solution detailed here.

Hope that helps