Angle brackets in Python [duplicate]

↘锁芯ラ 提交于 2019-12-07 04:50:17

问题


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': {},

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

Thanks


回答1:


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)


来源:https://stackoverflow.com/questions/37762596/angle-brackets-in-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!