2016-06-11 148 views
3

我想用scapy來製作數據包。當通過IP()類成員瀏覽時,我遇到以下代碼成語:Python中的尖括號

'fieldtype': { 

    'frag': <Field (IP,IPerror).frag>, 
    'src': <Field (IP,IPerror).src>, 
    'proto': <Field (IP,IPerror).proto>, 
    'tos': <Field (IP,IPerror).tos>, 
    'dst': <Field (IP,IPerror).dst>, 
    'chksum': <Field (IP,IPerror).chksum>, 
    'len': <Field (IP,IPerror).len>, 
    'options': <Field (IP,IPerror).options>, 
    'version': <Field (IP,IPerror).version>, 
    'flags': <Field (IP,IPerror).flags>, 
    'ihl': <Field (IP,IPerror).ihl>, 
    'ttl': <Field (IP,IPerror).ttl>, 
    'id': <Field (IP,IPerror).id>}, 
    'time': 1465637588.477862, 
    'initialized': 1, 
    'overloaded_fields': {}, 

我對Python相對來說比較新。有人能向我解釋尖括號在每個字段類型定義中的用途嗎?

我一直在試圖找出這個自己使用下面的文檔,但完全卡住了。

Scapy 2.3.1

由於

+1

它只是對象的字符串表示形式,而不是實際的Python語法。 –

回答

1

repr當施加至Field實例使用用於__repr__以下定義這是不Python語法的來源。

def __repr__(self): 
    return "<Field (%s).%s>" % (",".join(x.__name__ for x in self.owners),self.name)