[Tutor] python and kiviat diagrams
Emile van Sebille
emile at fenx.com
Thu Dec 24 00:44:00 CET 2009
On 12/23/2009 2:27 PM Albert-Jan Roskam said...
> 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?
Not when defining factory creation functions which a quick look at this
code confirms that's what this says it's doing. They're often used when
creating compatibility layers to provide common named methods.
> Why not use a class instance inside the function instead?
That's a question for the original developer. You can get to the same
place in many different ways, and the concept of 'There should be one--
and preferably only one --obvious way to do it.' no longer commands the
same respect at this level of design.
> No methods of the
> class can currently be inherited outside the scope of the function, right?
Yes -- the class has served it's purpose once it's been registered. It
can of course be reached and could likely be invoked and could even
possibly be used to create new instances, but you'd have to introspect
and find the right __class__ attribute. Both this level of
introspection and factory methods are intermediate to advanced
techniques that most of us will only rarely need, but it's good to know
it can be done.
Emile
More information about the Tutor
mailing list