import guards?

Phil Thompson phil at riverbankcomputing.co.uk
Thu May 8 06:15:23 EDT 2003


On Thursday 08 May 2003 10:46 am, Littlejohn septante cinq wrote:
> "A. Lloyd Flanagan" <alloydflanagan at attbi.com> wrote in message
> news:a8b7f07a.0305070602.3a9761eb at posting.google.com...
>
> > Oh, come on, there's only 2,746 symbols in wxPython.wx.  Why not list
> > them
>
> all?
>
> > ;-)
>
> How true:
> >>> from wxPython import wx
> >>> help(wx)
>
> After a while : a message  not enough memory (1)
> And I cannot reproduce this error today, Windows is more at ease, I don't
> know why
>
> I consider that to put more than a hundred symbols in the same
> module/namespace a major design flaw. Moreover, there is not any doc string
> at all. Is it impossible to inject documentation in the code generated by
> SWIG ? And how is pyQt in this regard ?

The biggest problem for PyQt is class methods - there are about 6000 of them. 
Under the covers they are implemented as "lazy" methods. The instance getattr 
function is subverted (transparently - you can still have a separate 
__getattr__ method) so that if a method isn't found it is looked up in a 
static table. If found then the normal Python object is created and placed in 
the instance dictionary - which acts as a cache.

The disadvantage of this approach is that introspection becomes rather 
difficult - methods magically appear once they are explicitly referenced.

The advantage is that it makes something the size of PyQt practical. "import 
qt" takes less that 0.5 seconds on my 750MHz laptop. Memory size is also 
reduced significantly.

Phil





More information about the Python-list mailing list