Search code examples
pythonstatic-methodsattributeerror

Call a static method from other class in python


I have a python file with name Pqr.py which contains a class holding a static method.

import subprocess

class Pqr:

    @staticmethod
    def callTheService(a,b,c):
       subprocess.call(a,b,c)

Now I am trying to access this static method from another class which is in other python file. Both .py files are located in same directory. The code in second file is,

import Pqr

class Rst:
    Pqr.callTheService("a", "b", "c")

When I try to run this, I get an error of AttributeError: module 'Pqr' has no attribute 'callTheService'

Could you please help me solve this error?


Solution

  • I solved the problem reading comments. I imported the class within the module. Here is the sample working code.

    from Pqr import Pqr
    
    class Rst:
        Pqr.callTheService("a", "b", "c")