Python doubts syntax

1

Galera was studying python and saw on a website this line:

self.brotcl.plugins.runCustumcomand()

I know that self is referencing a class but and these three variables together like that?

    
asked by anonymous 25.10.2015 / 01:38

1 answer

4

self is referencing the object itself that has an attribute called brotctl .

self.brotctl is an object that has the plugins attribute.

Likewise, self.brotctl.plugins is an object that has method runCustomcomand .

An example implementation for what you present would be:

class Plugins:

    def runCustomcomand(self):
        pass    


class Brotctl:

    def __init__(self):
        self.plugins = Plugins()


class Exemplo:

    def __init__(self):
        self.broatctl = Broatctl()

    def run(self):
        self.broatctl.plugins.runCustomcomand()
    
25.10.2015 / 01:42