Home > database >  "methods inside method" - class python2
"methods inside method" - class python2

Time:07-22

I have this situation:

class ROUTER:
   ...
   def utils(self):
      def update(..) ...
      def reboot(..) ...

and I would like to invoke the sub methods of utils like this:

a=ROUTER()
a.utils.reboot()

but not work (AttributeError: 'function' object has no attribute 'inf). Where am I wrong? Thank you

CodePudding user response:

Here is an example of the basic approach you need in order to implement your desired interface:

class Utils:
    def update(...): ...

    def reboot(...): ...


class Router:
   def __init__(...):
       self.utils = Utils(...)


myrouter = Router()
myrouter.utils.reboot()
  • Related