Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #27186
| Date | 2012-08-16 19:27 +0200 |
|---|---|
| From | Thomas Bach <thbach@students.uni-mainz.de> |
| Subject | Re: Dynamically determine base classes on instantiation |
| References | (1 earlier) <502c3bc2$0$29978$c3e8da3$5496439d@news.astraweb.com> <mailman.3358.1345121602.4697.python-list@python.org> <502d0d74$0$6986$e4fe514c@news2.news.xs4all.nl> <mailman.3382.1345136056.4697.python-list@python.org> <ef388942-5cef-45cd-9c79-6e4a7f2f613a@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3385.1345138122.4697.python-list@python.org> (permalink) |
On Thu, Aug 16, 2012 at 10:03:51AM -0700, Richard Thomas wrote: > class Foo(object): > def __new__(cls, arg): > if isinstance(arg, list): > cls = FooList > elif isinstance(arg, dict): > cls = FooDict > return object.__new__(cls, arg) > > class FooList(Foo, list): > pass > > class FooDict(Foo, dict): > pass > > You could even have __new__ make these Foo* classes dynamically when > it encounters a new type of argument. > > Chard. Thanks for that one. Your solution just hit me like a punch in the face. I had something similar in my mind. But I could not work out how the mechanics behind it are working. Regards, Thomas
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Dynamically determine base classes on instantiation Thomas Bach <thbach@students.uni-mainz.de> - 2012-08-15 23:17 +0200
Re: Dynamically determine base classes on instantiation Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-08-16 00:16 +0000
Re: Dynamically determine base classes on instantiation Thomas Bach <thbach@students.uni-mainz.de> - 2012-08-16 14:52 +0200
Re: Dynamically determine base classes on instantiation Hans Mulder <hansmu@xs4all.nl> - 2012-08-16 17:10 +0200
Re: Dynamically determine base classes on instantiation Thomas Bach <thbach@students.uni-mainz.de> - 2012-08-16 18:54 +0200
Re: Dynamically determine base classes on instantiation Richard Thomas <chardster@gmail.com> - 2012-08-16 10:03 -0700
Re: Dynamically determine base classes on instantiation Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-08-16 17:49 +0000
Re: Dynamically determine base classes on instantiation Richard Thomas <chardster@gmail.com> - 2012-08-17 04:50 -0700
Re: Dynamically determine base classes on instantiation Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-08-17 14:53 -0400
Re: Dynamically determine base classes on instantiation Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-08-18 01:44 +0000
Re: Dynamically determine base classes on instantiation Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-08-18 11:36 +0100
Re: Dynamically determine base classes on instantiation Richard Thomas <chardster@gmail.com> - 2012-08-16 10:03 -0700
Re: Dynamically determine base classes on instantiation Thomas Bach <thbach@students.uni-mainz.de> - 2012-08-16 19:27 +0200
Re: Dynamically determine base classes on instantiation Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-08-16 18:04 +0000
Re: Dynamically determine base classes on instantiation Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-08-16 12:29 -0400
Re: Dynamically determine base classes on instantiation Richard Thomas <chardster@gmail.com> - 2012-08-16 10:09 -0700
Re: Dynamically determine base classes on instantiation Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-08-16 17:45 +0000
Re: Dynamically determine base classes on instantiation Thomas Bach <thbach@students.uni-mainz.de> - 2012-08-16 19:18 +0200
Re: Dynamically determine base classes on instantiation Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-08-16 18:08 +0000
csiph-web