我尝试读取输入文件
Myfile = list(input("Please enter a filename with full dir: "))
fp = open(Myfile)
sstr = fp.read()
但始终显示错误:
"D:\Program Files\Python\python.exe" D:/Onebox/Python/my_help_doc/guo.py
Please enter a filename with full dir: 'E:\个人\郭周诺\Python\guo-python.txt'
Traceback (most recent call last):
File "D:/Onebox/Python/my_help_doc/guo.py", line 7, in <module>
fp = open(Myfile)
TypeError: expected str, bytes or os.PathLike object, not list
Process finished with exit code 1
对于
open
内置函数,应该使用类似路径的对象而不是列表作为参数从docs开始:
可以使用字符串作为
open
函数的参数:相关问题 更多 >
编程相关推荐