[Solved] Read and print a user selected file’s contents [closed]


For what you are trying to do, a better method would be:

import os

def print_file_contents(file_path):
    assert os.path.exists(file_path), "File does not exist: {}".format(file_path)
    with open(file_path) as f:
        print (f.read())

user_input = raw_input("Enter a file path: ") # just input(...) in Python 3+
print_file_contents(user_input)

solved Read and print a user selected file’s contents [closed]