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?
Pqr.py? You need to access the class not the module, so usePqr.Pqr.callTheService. In python, you do not generally give the module the same name as a class (Python != Java). BTW, this would have been more obvious if you follow Python naming conventions. Generally, you uselower_casefor module names, and avoidcamelCaseat all costs!Pqrshould be a class to begin with, and this is a toy example.