【发布时间】:2021-11-18 07:24:41
【问题描述】:
我想通过 cmd 输入文件名。所以我用了
file1=input("File Scan1: ")
但是当我输入一个文件名链接 File1.xml 时,Python 会告诉我:
Traceback (most recent call last):
File "compare.py", line 6, in <module>
file1=input("File Scan1: ")
File "<string>", line 1, in <module>
AttributeError: type object 'file' has no attribute 'xml'```
How can i solve this?
【问题讨论】:
-
该代码本身不会导致该错误。但是,如果您之前已将某些内容分配给名为 input 的变量,那么它将执行此操作。请显示更多您的代码
-
您以某种方式在 Python 2.x 下运行此代码。在这些旧版本上,您需要使用
raw_input()而不是input()。
标签: python python-3.x input filenames