[PyQt] SIP newbie question 2

Jens Thoms Toerring jt at toerring.de
Wed Jul 6 16:49:37 BST 2011

On Wed, Jul 06, 2011 at 05:21:19PM +0200, Johan Råde wrote:
> I have a class that defines the methods
>   int size() const;
>   const char* operator[int pos] const;
>   operator bool() const;
> I want to rename these methods
>   __len__
>   __getitem__
>   __nonzero__
> when I  export them.
> With SWIG I can do that with the %rename directive.
> How do I do that with SIP?

That's what the PyName function annotation is for:

int size( ) const /PyName=__len__/;

or, if you want to also retain the original name of the
function simply add 

int __len__( ) const
    sipRes = sipCpp->size( );

In the special case of the__len__()-function there's
(since 4.10.3) even a special annotation for that:

int size( ) const /__len__/;

See also

                             Refards, Jens
  \   Jens Thoms Toerring  ________      jt at toerring.de
   \_______________________________      http://toerring.de

More information about the PyQt mailing list