Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'class,': 0.07; 'instance.': 0.09; 'messing': 0.09; 'question?': 0.09; 'tuple': 0.09; 'zero.': 0.09; '(the': 0.15; 'library': 0.15; 'dig': 0.16; 'foo(object):': 0.16; 'fruit': 0.16; "he'll": 0.16; 'helpers': 0.16; 'hypothetical': 0.16; 'statement.': 0.16; 'wrote:': 0.17; 'instance': 0.17; 'define': 0.20; 'subject:skip:i 10': 0.22; "i'd": 0.22; 'pass': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'thanks!': 0.26; 'object,': 0.27; 'replace': 0.27; 'parent': 0.29; 'class': 0.29; 'this.': 0.29; 'classes': 0.30; 'certain': 0.33; 'to:addr:python-list': 0.33; 'form.': 0.33; 'another': 0.33; 'whatever': 0.35; 'pm,': 0.35; 'subject:?': 0.35; 'something': 0.35; 'there': 0.35; 'add': 0.36; 'but': 0.36; 'child': 0.36; 'does': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'things': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'your': 0.60; 'license': 0.65; 'said:': 0.65; 'god': 0.66; "driver's": 0.84; 'flies': 0.84; 'holes': 0.84; 'me!': 0.84; '000': 0.93; 'divided': 0.93 Date: Fri, 03 Aug 2012 23:14:11 -0400 From: "Steven W. Orr" Organization: SysLang, Inc. User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.28) Gecko/20120306 Thunderbird/3.1.20 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Deciding inheritance at instantiation? References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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: 55 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1344050059 news.xs4all.nl 6842 [2001:888:2000:d::a6]:57028 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:26469 On 8/3/2012 4:48 PM, Tobiah wrote: > I have a bunch of classes from another library (the html helpers > from web2py). There are certain methods that I'd like to add to > every one of them. So I'd like to put those methods in a class, > and pass the parent at the time of instantiation. Web2py has > a FORM class for instance. I'd like to go: > > my_element = html_factory(FORM) > > Then my_element would be an instance of my class, and also > a child of FORM. > > I started messing with decorators, but it became difficult > for me to visualise how to do this. > > Thanks! > > Toby Your class inherits from whatever is in the class statement. class Foo(object): pass Here, Foo inherits from object, but you can replace object with any tuple of classes which can be redefined before instantiation. class Base1(object): pass class Base2(object): pass Now we can define Foo2 to inherit from something that better be a tuple of classes at instantiation time. class Foo2(bases): pass bases = (Base1,) foo2 = Foo2() # foo2 is a Foo2 which inherits from Base1. bases = (Base1, Bace2) foob1b2 = Foo2() # foob1b2 is a Foo2 which inherits from Base1 and Base2. Who was it who said: "Give a man a shovel and he'll dig himself one helluva hole"? -- Time flies like the wind. Fruit flies like a banana. Stranger things have .0. happened but none stranger than this. Does your driver's license say Organ ..0 Donor?Black holes are where God divided by zero. Listen to me! We are all- 000 individuals! What if this weren't a hypothetical question? steveo at syslang.net