i writing some code to do device testing at my work. testing is related to date and time, so naturally i decided to create a class that inherits from datetime.datetime. main reason is that i need to add, subtract and compare datetime objects and datetime.datetime allows me to do that. here is the code:
class LTime(datetime.datetime): TOLERANCE = 10 def __new__(self, year, month, day, *args): if year == 0: year = 2000 return super().__new__(self, year, month, day, *args) def modify(self): self = self.replace(2012, 12, 12) print(self) def main(): mytime = LTime.now() mytime.modify() print(mytime) if __name__ == '__main__': main() the problem that i see is that i'm not able to modify date and time because it seems that those attributes are immutable. another problem that i see is in the modify() routine. if you print mytime the date and time are still old. can anybody explain why this is happening and if it is even possible to achieve what i'm trying to achieve, which is to change self.date and self.time any help is appreciated.
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor