【问题标题】:Cant input(file.xml) in Python无法在 Python 中输入(file.xml)
【发布时间】: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


【解决方案1】:

这是我的代码。它正在比较 2 次 nmap 扫描并确定实际上未使用的 mac 地址

from xml.dom import minidom


print("Compare 2 Nmap Mac Scans /n")
file1=input("File Scan1: ")
file2=input("File Scan2: ")

xmldoc1=minidom.parse(file1)
hosts=xmldoc1.getElementsByTagName('host')
xmldoc2=minidom.parse(file2)

maclist1=[]
maclist2=[]

for host in hosts:
    adress=host.getElementsByTagName("address")
    
    if len(adress) > 1:  
    
        mac=adress[1].attributes["addr"]
        MAC=mac.value
        maclist1.append(MAC)
                

hosts=xmldoc2.getElementsByTagName('host')


for host in hosts:
    adress=host.getElementsByTagName("address")
    
    if len(adress) > 1:  
    
        mac=adress[1].attributes["addr"]
        MAC=mac.value
        maclist2.append(MAC)
        
for i in maclist1:
    for j in maclist2:
        if(i!=j):
            print(i)

【讨论】:

  • 这看起来不像是一个答案。如果您想澄清问题,请编辑问题。即使它旨在作为答案,也不清楚为什么它解决了问题中的问题。
  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 1970-01-01
  • 2019-12-27
  • 2019-11-11
  • 2020-01-09
  • 1970-01-01
  • 2021-08-22
  • 2019-09-26
  • 1970-01-01
相关资源
最近更新 更多