using datetime containers

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Sat Nov 8 14:22:04 EST 2008


On Sat, 08 Nov 2008 08:07:15 -0800, indika wrote:

> John Machin wrote:
>> On Nov 8, 6:06�pm, indika <indikabandar... at gmail.com> wrote:
>> > Or else, I would have expected the datatime.date object has a
>> > writeable data member, so that iterating a calender with
>> > itermonthdates would allow me to access that data member.
>>
>> Sorry, I can't begin to guess what you mean by that.
> 
> I was referring to something like this
> 
> eg. in an Image processing lib
> 
> struct Image
> {
> char* p_Data; // image data
> int i_DataLen; // length of data
> void* p_UserData; // user attaches whatever }
> If the lib user attaches some struct related to image name, file
> location ... to p_UserData
> whenever a Image* is passed around the user has access to those.
> 
> Similarly, if a datetime.date object had an attribute which the user can
> access he could
> d1 = datetime.date.(2008, 1, 1)
> d1.UserData = x1 // hypothetical
> 
> d2 = datetime.date.(2008, 1, 2)
> d2.UserData = x2 // hypothetical
> 
> mylist.append([d1, d2])
> 
> Hope i'm making some sense :-)

You can subclass `datetime.date` and attach whatever attributes you 
want.  Be sure to overwrite `__new__()` because `datetime.date` objects 
are immutable.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list