Python function returning incorrect value -
i have decided start learning basic python... creating simple python file class, similar 1 used in .net framework.
so far, have following code:
import os class file: def __init__(self, filename=""): self.path = filename self.pathwithoutfilename, self.extwithdot = os.path.splitext(filename) self.ext = self.extwithdot.replace(".", "") def exists(): rbool = false if(os.path.exists(self.path)): rbool = true else: rbool = false return rbool def getpath(): return self.path test = file("/var/test.ad") print(test.path) print(test.extwithdot) print(test.ext) print(test.getpath) however, when run code, (i using python 2.7 on ubuntu) prints test.getpath function:
<bound method file.getpath of <__main__.file instance @ 0x3e99b00>> i have been changing , editing code while have not had success... getpath function return self.path value set earlier...
thanks
rodit
test.getpath return location of function or instance of class (in case of method). want add parens call function
print(test.getpath()) note, pointed out lukas graf, class implementation needs pass self identifier when defining methods if able called instantiated object, i.e.
def getpath(self): ... this allow do
test = file(parameter) test.getpath()
Comments
Post a Comment