Python 中的尖括号
Angle brackets in Python
我想使用 scapy 制作数据包。在查看 IP() class 成员时,我遇到了以下代码习惯用法:
'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 比较陌生。有人可以向我解释尖括号在每个字段类型定义中的作用吗?
我一直在尝试使用以下文档自行解决这个问题,但完全卡住了。
谢谢
repr
在应用于 Field
实例时使用以下 __repr__
的定义,这是 not Python 语法的来源。
def __repr__(self):
return "<Field (%s).%s>" % (",".join(x.__name__ for x in self.owners),self.name)
我想使用 scapy 制作数据包。在查看 IP() class 成员时,我遇到了以下代码习惯用法:
'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 比较陌生。有人可以向我解释尖括号在每个字段类型定义中的作用吗?
我一直在尝试使用以下文档自行解决这个问题,但完全卡住了。
谢谢
repr
在应用于 Field
实例时使用以下 __repr__
的定义,这是 not Python 语法的来源。
def __repr__(self):
return "<Field (%s).%s>" % (",".join(x.__name__ for x in self.owners),self.name)