我在 python 中使用静态函数时遇到问题。我有一个带有我的静态函数的类
class CFileSystemOperations(object):
....
....
def getRepositoryDirectory():
......
return sRepositoryDirectory
getRepositoryDirectory = staticmethod(getRepositoryDirectory)
然后我有另一个带有调用静态函数的类,我尝试了 2 个解决方案
class CMusicOrganizerView(object):
....
def __init__(self):
....
#first solution
sGuessedRepositoryTextfield = CFileSystemOperations().getRepositoryDirectory()
#second solution
sGuessedRepositoryTextfield = CFileSystemOperations.getRepositoryDirectory()
这里有错误:
sGuessedRepositoryTextfield = CFileSystemOperations().getRepositoryDirectory() TypeError: 'module' object is not callable
sGuessedRepositoryTextfield = CFileSystemOperations.getRepositoryDirectory() AttributeError:“模块”对象没有属性“getRepositoryDirectory”错误:模块:musicOrganizer 无法导入(文件:/..../musicOrganizer.py)。
有任何想法吗?先感谢您