我在python中使用靜態函數時遇到了問題。 我有一類與我的靜態函數Python中的靜態函數的錯誤2.7
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: 'module' object has no attribute 'getRepositoryDirectory' ERROR: Module: musicOrganizer could not be imported (file: /..../musicOrganizer.py).
有什麼想法嗎?預先感謝你
只是一個問題,文件(模塊)的名稱應該代表它們包含的類。所以我想以同樣的方式命名它們。模塊應該儘快命名? (從公約的角度來看) – axel
有關命名約定,請參見[PEP 8](http://www.python.org/dev/peps/pep-0008/#naming-conventions)。 –