[Python-Dev] slots and default values (original) (raw)

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