Static method
mk
mrkafk at gmail.com
Thu Feb 18 10:44:02 EST 2010
Bruno Desthuilliers wrote:
> I think you broke something somewhere. Assuming you're using Python 2.x
> (>= 2.3 IIRC), my above code works.
ARGH! Forgot the "delayed staticmethod" line -- in effect I called
staticmethod twice:
@staticmethod
def print_internal_date(filename):
f = open(filename + 'c', "rb")
data = f.read(8)
mtime = struct.unpack("<i", data[4:])
return time.asctime(time.gmtime(mtime[0]))
tagdata = {'compiled_fname': lambda x: x + 'c',
'size': os.path.getsize,
'internal_date': lambda x:
PYFileInfo.print_internal_date.__get__(x)
}
# HERE I BROKE IT
print_internal_date = staticmethod(print_internal_date)
def __init__(self, fname=None):
FileInfo.__init__(self,fname)
def __setitem__(self, key, value):
FileInfo.__setitem__(self, key, value)
if key == 'name' and value:
self.__get_props(value)
def testit(self, fname):
self.print_internal_date(fname+'c')
PYFileInfo.print_internal_date.__get__(fname+'c')
You're right. It works.
More information about the Python-list
mailing list