On Wed, Dec 23, 2009 at 5:27 PM, Albert-Jan Roskam <fo...@yahoo.com> wrote:
>
> I was studying the code on 
> http://matplotlib.sourceforge.net/examples/api/radar_chart.html.
> Isn't it very unusual that a class is defined within a function?

Unusual, but not un-heard of. Usually the function is a factory
function that returns the class to the caller. In this case the class
is registered as the handler for projections of type 'radar'.
Presumably RadarAxes is implementing a protocol (interface) that is
required by register_projection().

> Why not use a class instance inside the function instead?

Presumably register_projection() requires a class (strictly speaking,
it probably requires a callable that returns an instance of a class
that implements the required protocol). There don't seem to be any
docs for register_projection() so it's hard to know for sure what it
wants.

> No methods of the class can currently be inherited outside the scope of the 
> function, right?

Do you mean, the class cannot be subclassed? Not easily, only because
the function doesn't return the class. There is no inherent reason
this class could not be subclassed if a reference to the class were
available.

Kent
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to