Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #18657 > unrolled thread
| Started by | lars van gemerden <lars@rational-it.com> |
|---|---|
| First post | 2012-01-07 17:16 -0800 |
| Last post | 2012-01-08 02:48 -0800 |
| Articles | 7 — 4 participants |
Back to article view | Back to comp.lang.python
multiple inheritance from list and other class lars van gemerden <lars@rational-it.com> - 2012-01-07 17:16 -0800
Re: multiple inheritance from list and other class Chris Angelico <rosuav@gmail.com> - 2012-01-08 12:27 +1100
Re: multiple inheritance from list and other class 88888 Dihedral <dihedral88888@googlemail.com> - 2012-01-07 22:08 -0800
Re: multiple inheritance from list and other class 88888 Dihedral <dihedral88888@googlemail.com> - 2012-01-07 22:08 -0800
Re: multiple inheritance from list and other class Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-01-08 06:41 +0000
Re: multiple inheritance from list and other class Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-01-08 06:42 +0000
Re: multiple inheritance from list and other class lars van gemerden <lars@rational-it.com> - 2012-01-08 02:48 -0800
| From | lars van gemerden <lars@rational-it.com> |
|---|---|
| Date | 2012-01-07 17:16 -0800 |
| Subject | multiple inheritance from list and other class |
| Message-ID | <ea2fbcde-053b-4512-987a-564d9c9fd164@t13g2000yqg.googlegroups.com> |
Hello,
I have an error message i do not understand:
My code is in essence:
class A(object):
#no __new__ or __init__
def meth1(self, args):
#some code
def meth2(self, args):
#some code
class B(list, A)
pass
b = B([1,2,3,4])
error:
Traceback (most recent call last):
File "D:\Documents\Code\Eclipse\workspace\FlowTools\iteraids.py",
line 431, in <module>
testolist()
File "D:\Documents\Code\Eclipse\workspace\FlowTools\iteraids.py",
line 381, in testolist
b = B([0,1,2,3,4])
TypeError: B() takes exactly 2 arguments (1 given)
(adapted the error to the example classes)
Can anyone help/explain?
Cheers, Lars
[toc] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2012-01-08 12:27 +1100 |
| Message-ID | <mailman.4521.1325986029.27778.python-list@python.org> |
| In reply to | #18657 |
On Sun, Jan 8, 2012 at 12:16 PM, lars van gemerden <lars@rational-it.com> wrote: > Hello, > > I have an error message i do not understand: > > My code is in essence: > > b = B([1,2,3,4]) > > error: > b = B([0,1,2,3,4]) > TypeError: B() takes exactly 2 arguments (1 given) Your code doesn't quite match your error message, and the code as posted (with 'pass' in the method bodies to make it compile) works fine. Can you derive a minimal test-case that actually produces the error in question, and then post the actual code and error? Also - what version of Python are you using? Chris Angelico
[toc] | [prev] | [next] | [standalone]
| From | 88888 Dihedral <dihedral88888@googlemail.com> |
|---|---|
| Date | 2012-01-07 22:08 -0800 |
| Message-ID | <mailman.4523.1326002905.27778.python-list@python.org> |
| In reply to | #18658 |
A list is a container. Chris Angelico於 2012年1月8日星期日UTC+8上午9時27分06秒寫道: > On Sun, Jan 8, 2012 at 12:16 PM, lars van gemerden <la...@rational-it.com> wrote: > > Hello, > > > > I have an error message i do not understand: > > > > My code is in essence: > > > > b = B([1,2,3,4]) > > > > error: > > b = B([0,1,2,3,4]) > > TypeError: B() takes exactly 2 arguments (1 given) > > Your code doesn't quite match your error message, and the code as > posted (with 'pass' in the method bodies to make it compile) works > fine. Can you derive a minimal test-case that actually produces the > error in question, and then post the actual code and error? Also - > what version of Python are you using? > > Chris Angelico The class is defined in a silly way. In python declaring a class with only trivial properties added is not very python at all. Just let an object obtain new properties to save the troubles of deriving a lot classes not different too much.
[toc] | [prev] | [next] | [standalone]
| From | 88888 Dihedral <dihedral88888@googlemail.com> |
|---|---|
| Date | 2012-01-07 22:08 -0800 |
| Message-ID | <2328.1302.1326002902374.JavaMail.geo-discussion-forums@prnp7> |
| In reply to | #18658 |
A list is a container. Chris Angelico於 2012年1月8日星期日UTC+8上午9時27分06秒寫道: > On Sun, Jan 8, 2012 at 12:16 PM, lars van gemerden <la...@rational-it.com> wrote: > > Hello, > > > > I have an error message i do not understand: > > > > My code is in essence: > > > > b = B([1,2,3,4]) > > > > error: > > b = B([0,1,2,3,4]) > > TypeError: B() takes exactly 2 arguments (1 given) > > Your code doesn't quite match your error message, and the code as > posted (with 'pass' in the method bodies to make it compile) works > fine. Can you derive a minimal test-case that actually produces the > error in question, and then post the actual code and error? Also - > what version of Python are you using? > > Chris Angelico The class is defined in a silly way. In python declaring a class with only trivial properties added is not very python at all. Just let an object obtain new properties to save the troubles of deriving a lot classes not different too much.
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2012-01-08 06:41 +0000 |
| Message-ID | <4f093a8a$0$29966$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #18663 |
On Sat, 07 Jan 2012 22:08:22 -0800, 88888 Dihedral wrote: [...] > The class is defined in a silly way. > In python declaring a class with only trivial properties added is not > very python at all. The example given looks like a Mixin class, which is perfectly acceptable in Python. -- Steven
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2012-01-08 06:42 +0000 |
| Message-ID | <4f093ab9$0$29966$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #18657 |
On Sat, 07 Jan 2012 17:16:22 -0800, lars van gemerden wrote: > Hello, > > I have an error message i do not understand: > > My code is in essence: The code you give works fine. It does not show the error you say it does. Please test your code before posting and ensure it actually fails the way you expect. It is perfectly fine to use multiple inheritance in the way you show. Here is an even simpler example: py> class Spam(object): ... pass ... py> class Ham(list, Spam): ... pass ... py> py> h = Ham([1, 2, 3]) py> And no exception is raised. -- Steven
[toc] | [prev] | [next] | [standalone]
| From | lars van gemerden <lars@rational-it.com> |
|---|---|
| Date | 2012-01-08 02:48 -0800 |
| Message-ID | <a40cec34-6586-4b5a-92db-e3c6afc7e89c@n6g2000vbz.googlegroups.com> |
| In reply to | #18665 |
On Jan 8, 7:42 am, Steven D'Aprano <steve +comp.lang.pyt...@pearwood.info> wrote: > On Sat, 07 Jan 2012 17:16:22 -0800, lars van gemerden wrote: > > Hello, > > > I have an error message i do not understand: > > > My code is in essence: > > The code you give works fine. It does not show the error you say it does. > Please test your code before posting and ensure it actually fails the way > you expect. > > It is perfectly fine to use multiple inheritance in the way you show. > Here is an even simpler example: > > py> class Spam(object): > ... pass > ... > py> class Ham(list, Spam): > ... pass > ... > py> > py> h = Ham([1, 2, 3]) > py> > > And no exception is raised. > > -- > Steven Sorry for wasting you time, I found the error (had "def" instead of "class" before B in the example), sorry about not testing, shouldn't post at 2:00 AM. Thanks all the same, Lars
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web