Problems with first try subclassing
Driver, David
DDriver at covercraft.com
Wed May 21 15:34:33 EDT 2003
Howdy!
I am relatively new to Python and I thought that I would give subclassing a
try today, so I started with something simple. We have some old systems that
store dates in YYYYMMDD format. In example: January 25, 1975 would look like
'19740125'. This was done so that if the data was cast to either string or
text it would sort properly.
When I call GetMyDate it works fine. When I call LoadMyDate, I receive no
errors but the object does not update it's value. This process works fine in
the shell:
>>> m = '20031231'
>>> m
'20031231'
>>> s=(m[:4],m[4:6],m[6:8])
>>> s
('2003', '12', '31')
Here is the code that I am working on.
import datetime
class myDate(datetime.date):
def GetMyDate(self): return self.isoformat().replace('-','')
def LoadMyDate(self,m): self=(m[:4],m[4:6],m[6:8])
td = myDate.today()
print td.GetMyDate()
td.LoadMyDate('20031231')
print td.GetMyDate()
There is probably something basic that I am missing, butI can't seem to
figure out what it is.
Thanks for all of your help!
More information about the Python-list
mailing list