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: 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 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> <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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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: ...