Python 3.x 如何通过用户输入打开文件?

Python 3.x 如何通过用户输入打开文件?,python-3.x,Python 3.x,这就是我到目前为止所尝试的: print('''You will have to enter a file name Once the file name has been entered, the program will then print out your ASCII art''') file_name = input('Enter file name: ') with open(file_name) as file_handle: for line in file_handle

这就是我到目前为止所尝试的:

print('''You will have to enter a file name
Once the file name has been entered, the program will then print out your ASCII art''')
file_name = input('Enter file name: ')
with open(file_name) as file_handle:
    for line in file_handle:
        for x in f:
            print(x)

一个for循环应该按照注释从代码中删除,并且应该打印行

print('''You will have to enter a file name
Once the file name has been entered, the program will then print out your ASCII art''')
file_name = input('Enter file name: ')
with open(file_name) as file_handle:
    for line in file_handle:
        #for x in f:
        print(line)