2016-06-11 150 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)