如何通过用户输入打开文件?

时间:2019-05-23 12:46:09

标签: 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:
        for x in f:
            print(x)

1 个答案:

答案 0 :(得分:0)

一个已注释的循环应该从代码中删除,并且应该打印行。

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)