Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #15450

Re: How to mix-in __getattr__ after the fact?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'read-only': 0.07; 'received:edu.au': 0.07; 'wrapper': 0.07; '(it': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'def': 0.14; '**kwargs)': 0.16; '**kwargs):': 0.16; '*args,': 0.16; 'class:': 0.16; 'wrote:': 0.18; 'correct,': 0.23; 'header:In-Reply-To:1': 0.23; 'class': 0.29; 'binding': 0.30; 'example': 0.30; 'subject:?': 0.31; 'thanks': 0.31; 'pm,': 0.31; 'to:addr:python- list': 0.32; 'header:User-Agent:1': 0.33; 'rules': 0.33; 'header:X -Complaints-To:1': 0.33; 'try:': 0.34; 'subject:How': 0.35; '...': 0.36; 'received:au': 0.36; 'another': 0.36; 'received:org': 0.37; 'except': 0.39; 'everyone': 0.39; 'subject:: ': 0.39; 'to:addr:python.org': 0.39; 'skip:_ 10': 0.40; 'did': 0.40; 'huge': 0.60; 'special': 0.67
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Lie Ryan <lie.1296@gmail.com>
Subject Re: How to mix-in __getattr__ after the fact?
Date Tue, 08 Nov 2011 15:17:14 +1100
References <4630c4d0-86bc-4295-8bbb-6f58415191c8@v15g2000vbm.googlegroups.com> <4EAAF264.1050307@stoneleaf.us> <mailman.2298.1319855210.27778.python-list@python.org> <8bc11029-860e-4d3a-8770-062e16e31514@j39g2000yqc.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host cpmon.mq.edu.au
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1
In-Reply-To <8bc11029-860e-4d3a-8770-062e16e31514@j39g2000yqc.googlegroups.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2529.1320725851.27778.python-list@python.org> (permalink)
Lines 20
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1320725851 news.xs4all.nl 6947 [2001:888:2000:d::a6]:53538
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:15450

Show key headers only | View raw


On 10/31/2011 11:01 PM, dhyams wrote:
>
> Thanks for all of the responses; everyone was exactly correct, and
> obeying the binding rules for special methods did work in the example
> above.  Unfortunately, I only have read-only access to the class
> itself (it was a VTK class wrapped with SWIG), so I had to find
> another way to accomplish what I was after.
>

As a big huge hack, you can always write a wrapper class:

class Wrapper(object):
     def __init__(self, *args, **kwargs):
         self.__object = MySWIGClass(*args, **kwargs)
     def __getattr__(self, attr):
         try:
             return getattr(self.__object, attr)
         except AttributeError:
             ...

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How to mix-in __getattr__ after the fact? dhyams <dhyams@gmail.com> - 2011-10-28 10:34 -0700
  Re: How to mix-in __getattr__ after the fact? Jerry Hill <malaclypse2@gmail.com> - 2011-10-28 14:14 -0400
  Re: How to mix-in __getattr__ after the fact? Ethan Furman <ethan@stoneleaf.us> - 2011-10-28 11:20 -0700
  Re: How to mix-in __getattr__ after the fact? Lie Ryan <lie.1296@gmail.com> - 2011-10-29 13:26 +1100
    Re: How to mix-in __getattr__ after the fact? dhyams <dhyams@gmail.com> - 2011-10-31 05:01 -0700
      Re: How to mix-in __getattr__ after the fact? DevPlayer <devplayer@gmail.com> - 2011-11-01 22:50 -0700
      Re: How to mix-in __getattr__ after the fact? Lie Ryan <lie.1296@gmail.com> - 2011-11-08 15:17 +1100
        Re: How to mix-in __getattr__ after the fact? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-11-08 05:58 +0000
      Re: How to mix-in __getattr__ after the fact? Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2011-11-08 11:21 +0100

csiph-web