Created
June 2, 2011 18:06
-
-
Save santa4nt/1004925 to your computer and use it in GitHub Desktop.
Demonstrate usage of ctypes Structure to synthesize a C struct
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ctypes import * | |
from ctypes.wintypes import * | |
class SYSTEMTIME(Structure): | |
"""See: WinBase.h""" | |
_fields_ = [ | |
('wYear', WORD), | |
('wMonth', WORD), | |
('wDayOfWeek', WORD), | |
('wDay', WORD), | |
('wHour', WORD), | |
('wMinute', WORD), | |
('wSecond', WORD), | |
('wMilliseconds', WORD), | |
] | |
def __str__(self): | |
return '%4d/%02d/%02d %02d:%02d:%02d.%03d' % \ | |
(self.wYear, self.wMonth, self.wDay, | |
self.wHour, self.wMinute, self.wSecond, self.wMilliseconds) | |
def __repr__(self): | |
return 'SYSTEMTIME(%4d,%02d,%02d,%02d,%02d,%02d,%d)' % \ | |
(self.wYear, self.wMonth, self.wDay, | |
self.wHour, self.wMinute, self.wSecond, self.wMilliseconds) | |
def __lt__(self, other): | |
for attrstr, _ in self._fields_: | |
if getattr(self, attrstr) > getattr(other, attrstr): | |
return False | |
return True | |
def __gt__(self, other): | |
for attrstr, _ in self._fields_: | |
if getattr(self, attrstr) < getattr(other, attrstr): | |
return False | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment