Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angle brackets in Python [duplicate]

Tags:

python

scapy

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

like image 450
zan Avatar asked Jun 11 '16 10:06

zan


People also ask

What are [] used for in Python?

[] (Index brackets) Index brackets ([]) have many uses in Python. First, they are used to define "list literals," allowing you to declare a list and its contents in your program. Index brackets are also used to write expressions that evaluate to a single item within a list, or a single character in a string.

What is [] called in Python?

() parentheses are used for order of operations, or order of evaluation, and are referred to as tuples. [] brackets are used for lists. List contents can be changed, unlike tuple content. {} are used to define a dictionary in a "list" called a literal.

What is the difference between using angular brackets and double quotes?

When you use angle brackets, the compiler searches for the file in the include path list. When you use double quotes, it first searches the current directory (i.e. the directory where the module being compiled is) and only then it'll search the include path list.


1 Answers

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)
like image 75
Dan D. Avatar answered Sep 24 '22 21:09

Dan D.