Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 314
swarupmishal Avatar asked Aug 21 '26 18:08

swarupmishal


1 Answers

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")
like image 136
swarupmishal Avatar answered Aug 24 '26 09:08

swarupmishal