0

I have various class in a module that execute some operation.

Since all of them require to connect to a remote server to execute these operation, I thought that is not convenient to have a ton of code repeated, so I put the connection part in a function.

Now I would like to make this function available to all the classes in this module, but not visible from outside. How do you do this in Python?

class A(obj):
    connect(ip)

class B(obj):
    connect(ip)

def connect(self, ip):
    # connect to host
  • My question is different; I am not looking at how to make a function private, and then import it in a different class. I am looking at how to make a function visible only to the classes in the same module, so if I have class A and B, and the private function in the same module; I can call the function in A or B, but when I import the module, it won't be visible (so only A and B will be visible). –  Jun 08 '15 at 22:06
  • Have them both inherit a method from an abstract (parent) class. – Brent Washburne Jun 08 '15 at 22:49

0 Answers0