Python中的尖括号

2024-10-01 11:33:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用scapy来制作数据包。在查看IP()类成员时,我遇到了以下代码习惯用法:

'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

谢谢


Tags: ipsrcfieldlenversiondstoptionsproto
1条回答
网友
1楼 · 发布于 2024-10-01 11:33:45

当应用于Field实例时,repr使用以下定义来表示__repr__,这是not Python语法的来源。在

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

相关问题 更多 >