2017-08-25 50 views
0

我使用mapp方法從列表(str)到列表(int),但是當我調用scapy庫時。我沒有得到相同的結果。Scapy庫修改方法映射()

我使用Python 2.7.13

print "E: {}".format(map(int, ['1', '2'])) 

回報

E: [1, 2] 

from scapy.all import * 
print "E: {}".format(map(int, ['1', '2'])) 

回報

E: <itertools.imap object at 0x0405E730 
+0

我用_python 2.7.13_試過了你的代碼,對我來說工作得很好......你確定'scapy'會導致這個問題嗎? – coder

+0

是的。該代碼適用於Linux,但不適用於Windows。 你用Windows試過嗎? – Zer0

+0

Scapy似乎在使用itertools.imap而不是map。不要使用明星導入,像'從scapy導入所有東西's' – geckos

回答

2

當你將一個模塊導入Python中的命名空間時,存在這種風險。

在這裏,您使用的是Scapy的開發版本,這是一個錯誤(在導入Scapy時,您不應該導入Scapy的map(),這是six模塊提供的模塊)。你應該可能report it

但是,爲了避免這種情況,您應該在自己的名稱空間中導入Scapy。例如:

from scapy import all as scapy 
scapy.IP()/scapy.ICMP() # this will work 
print "E: {}".format(map(int, ['1', '2'])) # this will display a list 
+0

謝謝。這是我會做的 – Zer0