any interest in type-scoped static constants?

Alex Martelli aleaxit at yahoo.com
Mon Mar 12 04:28:07 EST 2001


"Alexander Semenov" <sav at ulmen.mv.ru> wrote in message
news:98gs2i$2vtp$1 at news1.simtel.ru...
    [snip]
> > If I create an extension type for Point, I can't do this:
> >
> > p = Point.ZERO
>
> In Python:
>
> class Point:
>     def __init(self, x, y): pass
>
> Point.ZERO = Point(0,0)
>
> Then you can write p = Point.ZERO.
> It's even simpler and clearer then C++

Yes, but it doesn't apply to *extension types* (which you write
in C or C++, then *use* from Python), only to classes you write
in Python itself.

One solution is, indeed, to split the extension into two parts:
one, written in C or C++, is in some _foo.pyd (the leading _
suggests it's internal-use-only), and it's wrapped by a foo.py
which adds the niceties -- a rather popular solution (you only
use C or C++ for truly speed-critical parts).

Another is to use the Boost Python Library (www.boost.org) to
write your extension (in C++, only -- C is not supported).  BPL
uses the Beaudry Hook so the 'types' it exports are actually
'extension classes', so you can do a lot with them that would
not be feasible with 'just-types', including using attributes.


Alex






More information about the Python-list mailing list