I am new to Python. I came across Python code in an OpenFlow controller that I am working on.
class SimpleSwitch(app_manager.RyuApp):
OFP_VERSIONS = [ofproto_v1_0.OFP_VERSION]
def __init__(self, *args, **kwargs):
super(SimpleSwitch, self).__init__(*args, **kwargs)
self.mac_to_port = {}
My questions are as follows.
Is __init__ the constructor for a class?
Is self the same as C++'s this pointer?
Does super(SimpleSwitch, self).__init__(*args, **kwargs) mean calling constructor for parent/super class?
Can you add a new member to self as mac_to_port? Or has that been already added and just being initialized here?
__init__ is the initialiser; __new__ is the constructor. See e.g. this question. self by convention, is the instance itself. SimpleSwitch in addition to what the parent class already has, an empty dictionary. If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With