I have defined a class to process a file but get the following error when I try to instantiate the class and pass the filename.
Let me know what would be the problem?
>>> class fileprocess:
... def pread(self,filename):
... print filename
... f = open(filename,'w')
... print f
>>> x = fileprocess
>>> x.pread('c:/test.txt')
Traceback (most recent call last):
File "", line 1, in
TypeError: unbound method pread() must be called with
fileprocess instance as first argument (got nothing instead)
x = fileprocessdoes not meanxis an instance offileprocess. It meansxis now an alias for thefileprocessclass.You need to create an instance, using the
().In addition, based on your original code, you could use
xto create class instances.