Python中的尖括号 [英] Angle brackets in Python
本文介绍了Python中的尖括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用 scapy 制作数据包.在查看 IP() 类成员时,我遇到了以下代码习惯用法:
I want to craft packets using scapy. When looking through the IP() class members I came across the following code idiom:
'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 比较陌生.有人可以向我解释尖括号在每个字段类型定义中的用途吗?
I am relatively new to Python. Can someone explain to me what purpose the angle brackets serve in each field type definition?
我一直在尝试使用以下文档自己解决这个问题,但完全卡住了.
I have been trying to figure out this myself using the following documentation but got completely stuck.
Scapy 2.3.1
谢谢
推荐答案
repr
当应用于 Field
实例时,对 __repr__
使用以下定义> 这是非 Python 语法的来源.
repr
when applied to a Field
instance uses the following definition for __repr__
which is the source of the not Python syntax.
def __repr__(self):
return "<Field (%s).%s>" % (",".join(x.__name__ for x in self.owners),self.name)
这篇关于Python中的尖括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文