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


Groups > comp.lang.python > #26456

Re: Deciding inheritance at instantiation?

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'class,': 0.07; 'instance.': 0.09; 'messing': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'terry': 0.09; '(the': 0.15; 'library': 0.15; 'bases,': 0.16; 'creation.': 0.16; 'helpers': 0.16; 'message-id:@dough.gmane.org': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'wrote:': 0.17; 'instance': 0.17; 'jan': 0.18; '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; 'header:X-Complaints-To:1': 0.28; '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; 'pm,': 0.35; 'subject:?': 0.35; 'there': 0.35; 'add': 0.36; 'received:org': 0.36; 'but': 0.36; 'child': 0.36; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'received:fios.verizon.net': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: Deciding inheritance at instantiation?
Date Fri, 03 Aug 2012 17:55:33 -0400
References <dOWSr.44251$Zl3.41187@newsfe06.iad>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-173-75-251-66.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20120713 Thunderbird/14.0
In-Reply-To <dOWSr.44251$Zl3.41187@newsfe06.iad>
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.2917.1344030962.4697.python-list@python.org> (permalink)
Lines 20
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1344030962 news.xs4all.nl 6871 [2001:888:2000:d::a6]:53557
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:26456

Show key headers only | View raw


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.

Use type(name, bases, content) for dynamic class creation.

-- 
Terry Jan Reedy

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


Thread

Deciding inheritance at instantiation? Tobiah <toby@tobiah.org> - 2012-08-03 13:48 -0700
  Re: Deciding inheritance at instantiation? Terry Reedy <tjreedy@udel.edu> - 2012-08-03 17:55 -0400
    Re: Deciding inheritance at instantiation? Tobiah <toby@tobiah.org> - 2012-08-06 10:42 -0700
  Re: Deciding inheritance at instantiation? Nobody <nobody@nowhere.com> - 2012-08-04 00:52 +0100
  Re: Deciding inheritance at instantiation? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-08-04 01:14 +0000
  Re: Deciding inheritance at instantiation? "Steven W. Orr" <steveo@syslang.net> - 2012-08-03 23:14 -0400
  Re: Deciding inheritance at instantiation? alex23 <wuwei23@gmail.com> - 2012-08-06 19:53 -0700
    Re: Deciding inheritance at instantiation? Tobiah <toby@tobiah.org> - 2012-08-07 10:52 -0700

csiph-web