为什么无法在python3中的“从scapy.all import *”之前“导入日期时间”?

问题描述 投票:0回答:1

[好,也许我遗漏了一些显而易见的东西,但是似乎我无法在导入“ scapy.all import *”之前导入日期时间。如果我在导入“ scapy.all import *”之后导入日期时间,则效果很好。我不明白。

示例;这不起作用...

    #!/usr/bin/env python3
    import os
    import datetime
    from scapy.all import *
    current_time = datetime.datetime.now()
    print(current_time)

但是这确实...

    #!/usr/bin/env python3
    import os
    from scapy.all import *
    import datetime
    current_time = datetime.datetime.now()
    print(current_time)

我正在使用Arch Linux,Python3和最新的Scapy。

python datetime import scapy
1个回答
0
投票

只是比较两个片段的猜测,但我怀疑您有一个namespace clash(欢迎您开始编程,这就是import *是不好的做法的原因。

scapy也具有datetime方法(没有比较两个软件包之间的定义),因此在这种情况下,导入顺序确实很重要,因为datetime的定义是overridden] >。

最好是只导入您需要的内容,例如:

#!/usr/bin/env python3
import os
import datetime
from scapy.all import sr, srp
current_time = datetime.datetime.now()
print(current_time)
© www.soinside.com 2019 - 2024. All rights reserved.