module not callable - why not?
Dave Benjamin
ramen at lackingtalent.com
Mon Apr 19 13:08:41 EDT 2004
In article <c56jph$rrk$05$1 at news.t-online.com>, Diez B. Roggisch wrote:
> Now usually I'd create a file called "quaternion.py", define my quaternion
> class in there and then import and create an instance like this:
>
> import quaternion
>
> q = quaternion.quaternion()
>
> Thats a lot to type. doing a
>
> from quaternion import quaternion
>
> would solve that - but AFAIK thats considered bad for some reasons.
Lately, I've become particularly fond of creating "factory" functions and
using those instead. For instance:
import Quaternion
q = Quaternion.create()
Aside from the less redundant naming style, factories are nice because they
allow you to return different classes of objects depending on their
parameters. For instance, Quaternion.create() might give you a
Quaternion.SimpleQuaternion, where Quaternion.create(foo='bar') might give
you a FooQuaternion instead. (I don't know much about quaternions, so I
can't give you a better example in that context.)
--
.:[ dave benjamin: ramen/[sp00] -:- spoomusic.com -:- ramenfest.com ]:.
: please talk to your son or daughter about parametric polymorphism. :
More information about the Python-list
mailing list