1

I have a class which has two methods(m_1 and m_2). The method m_1 makes a call to method m_2. Now i want to make sure that only m_1 can be called using a class insance and not m_2. How can i do that ?

class C_1:
  def m_1(self,z) :
    np.square(z)

  def m_2(self,x) :
    y = m_1(x)
    out = log(y)
    ret(out)

I want only m_2 to be callable i.e

C_1.m_2(x) # Valid

C_1.m_1(z) # m_1 shouldn't be allowed to call directly from the class instance

I know that the example here might not seem right as i can get square and log operation in a single method but, I am just using this simple example to formally put down what i expect to be done in the code.

Patrick Artner
  • 50,409
  • 9
  • 43
  • 69
cadip92
  • 151
  • 1
  • 7
  • 1
    Why do you make a method if you don't want it to be called? – mkrieger1 May 24 '19 at 10:06
  • it will be just for performing some common tasks for other methods.. there could be a couple of methods which can use that non-callable method – cadip92 May 24 '19 at 10:12
  • Ok i must admit i am a newbie in OOPS and after searching around the net i came to know that i actually want m_1 to be like a private method in Java – cadip92 May 24 '19 at 10:30
  • 1
    @PatrickArtner thanks for the solution "Defining private module functions in python".. that solved my problem – cadip92 May 24 '19 at 10:34

0 Answers0