Terry Carroll wrote:
> An example is if you wanted to create a "birthdate" class, which was just 
> like a regular date, but also included the birthstone that corresponded to 
> the date.  We could create a "birthdate" module that included a 
> "Birthdate" class:
> 
> ###############
> 
> import datetime
> 
> class Birthdate(datetime.date):
> 
>     def __init__(self, year, month, day):
>         stones = ["Garnet", "Amethyst", "Aquamarine",
>           "Diamond", "Emerald", "Perl",
>           "Ruby", "Python", "Sapphire",
>           "Opal", "Topaz", "Turquoise"]
>         self.birthstone = stones[month-1]

I think you are missing the line
   datetime.date.__init__(self, year, month, day)

somewhere in here.

I am very surprised that this works, my understanding was that 
datetime.date was immutable and required overriding __new__() rather 
than __init__(). But it does work...

Kent

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to