我想要创建一种实用工具类,它只包含可以通过name类前缀调用的静态方法。看来我做错了什么:)
这是我的类:
class FileUtility():
@staticmethod
def GetFileSize(self, fullName):
fileSize = os.path.getsize(fullName)
return fileSize
@staticmethod
def GetFilePath(self, fullName):
filePath = os.path.abspath(fullName)
return filePath
现在我的“主要”方法:
from FileUtility import *
def main():
path = 'C:\config_file_list.txt'
dir = FileUtility.GetFilePath(path)
print dir
我犯了个错误:unbound method GetFilePath() must be called with FileUtility instance as first argument (got str instance instead)
...
这里有几个问题:
TypeError: GetFilePath() takes exactly 1 argument (2 given)
新main
:
from FileUtility import *
def main():
objFile = FileUtility()
path = 'H:\config_file_list.txt'
dir = objFile.GetFilePath(path)
print dir
相似问题