[Python-Dev] __slots__ and default values

Delaney, Timothy C (Timothy) tdelaney@avaya.com
Wed, 14 May 2003 07:40:10 +1000


> From: Delaney, Timothy C (Timothy)=20
>=20
> class Pane (module): # Or whatever - you get the idea ;)
>=20
>     __slots__ =3D ('background', 'foreground', 'size',=20
> 'content', '__name__', '__file__')
>     __name__ =3D globals()['__name__']
>     __file__ =3D globals()['__file__']
>=20
>     background =3D 'black'
>     foreground =3D 'white'
>     size =3D (80, 25)
>=20
> import sys
> sys.modules[__name__] =3D Pane()

Hmm ... I was just wondering if we could use this technique to gain the =
advantages of fast lookup in other modules automatically (but =
optionally).

The idea is, the last line of your module includes a call which =
transforms your module into a module subclass instance with slots.

The functions in the module become methods which access the *class* =
instance variables (so they can modify them) but other modules can't.

A fair bit of work, and probably not worthwhile, but it's interesting to =
think about ;)

Tim Delaney