Out of curiosity, I tried passing using an invalid base
for a class. I can't explain why I got the error messages
I did. Can someone here enlighten me?
# Here I'm just curious
[color=blue][color=green][color=darkred]
>>> def spam(a, b):[/color][/color][/color]
.... return a+b
....[color=blue][color=green][color=darkred]
>>> class Spam(spam):[/color][/color][/color]
.... pass
....
Traceback (most recent call last):
File "<interacti ve input>", line 1, in ?
TypeError: function() argument 1 must be code, not str[color=blue][color=green][color=darkred]
>>>[/color][/color][/color]
# What's 'function'? Why is it called?
[color=blue][color=green][color=darkred]
>>> class Spam(1): pass[/color][/color][/color]
....
Traceback (most recent call last):
File "<interacti ve input>", line 1, in ?
TypeError: int() takes at most 2 arguments (3 given)[color=blue][color=green][color=darkred]
>>>[/color][/color][/color]
# what were the three given arguments?
# is it something I can redefine?
[color=blue][color=green][color=darkred]
>>> class Report:[/color][/color][/color]
.... def __getattr__(sel f, name):
.... print "Trying to get", repr(name)
.... raise AttributeError( name)
....[color=blue][color=green][color=darkred]
>>> class Spam(Report()): pass[/color][/color][/color]
....
Traceback (most recent call last):
File "<interacti ve input>", line 1, in ?
TypeError: this constructor takes no arguments[color=blue][color=green][color=darkred]
>>>[/color][/color][/color]
# doesn't look like it. What if I derive from an instance
# derived from object?
[color=blue][color=green][color=darkred]
>>> class Report(object):[/color][/color][/color]
.... def __getattr__(sel f, name):
.... print "Trying to get", repr(name)
.... raise AttributeError( name)
....[color=blue][color=green][color=darkred]
>>> class Spam(Report()): pass[/color][/color][/color]
....
Traceback (most recent call last):
File "<interacti ve input>", line 1, in ?
TypeError: default __new__ takes no parameters[color=blue][color=green][color=darkred]
>>>[/color][/color][/color]
# Okay.... Don't know what's going on, so I'll
# just fiddle around a bit.
[color=blue][color=green][color=darkred]
>>> class ABCD:[/color][/color][/color]
.... def __init__(self): pass
....[color=blue][color=green][color=darkred]
>>> class Spam(ABCD()): pass[/color][/color][/color]
....
Traceback (most recent call last):
File "<interacti ve input>", line 1, in ?
TypeError: __init__() takes exactly 1 argument (4 given)[color=blue][color=green][color=darkred]
>>> class ABCD:[/color][/color][/color]
.... def __init__(self, a): pass
....[color=blue][color=green][color=darkred]
>>> class Spam(ABCD()): pass[/color][/color][/color]
....
Traceback (most recent call last):
File "<interacti ve input>", line 1, in ?
TypeError: __init__() takes exactly 2 arguments (1 given)[color=blue][color=green][color=darkred]
>>>[/color][/color][/color]
# Which is it; 4 given or 1 given? And
# int had 3 passed to it....
[color=blue][color=green][color=darkred]
>>> class XYZZY:[/color][/color][/color]
.... def __init__(self, **args): print "I have", args
....[color=blue][color=green][color=darkred]
>>> class Spam(XYZZY()): pass[/color][/color][/color]
....
I have {}
Traceback (most recent call last):
File "<interacti ve input>", line 1, in ?
TypeError: __init__() takes exactly 1 argument (4 given)[color=blue][color=green][color=darkred]
>>>[/color][/color][/color]
Comments?
Andrew
dalke@dalkescie ntific.com
for a class. I can't explain why I got the error messages
I did. Can someone here enlighten me?
# Here I'm just curious
[color=blue][color=green][color=darkred]
>>> def spam(a, b):[/color][/color][/color]
.... return a+b
....[color=blue][color=green][color=darkred]
>>> class Spam(spam):[/color][/color][/color]
.... pass
....
Traceback (most recent call last):
File "<interacti ve input>", line 1, in ?
TypeError: function() argument 1 must be code, not str[color=blue][color=green][color=darkred]
>>>[/color][/color][/color]
# What's 'function'? Why is it called?
[color=blue][color=green][color=darkred]
>>> class Spam(1): pass[/color][/color][/color]
....
Traceback (most recent call last):
File "<interacti ve input>", line 1, in ?
TypeError: int() takes at most 2 arguments (3 given)[color=blue][color=green][color=darkred]
>>>[/color][/color][/color]
# what were the three given arguments?
# is it something I can redefine?
[color=blue][color=green][color=darkred]
>>> class Report:[/color][/color][/color]
.... def __getattr__(sel f, name):
.... print "Trying to get", repr(name)
.... raise AttributeError( name)
....[color=blue][color=green][color=darkred]
>>> class Spam(Report()): pass[/color][/color][/color]
....
Traceback (most recent call last):
File "<interacti ve input>", line 1, in ?
TypeError: this constructor takes no arguments[color=blue][color=green][color=darkred]
>>>[/color][/color][/color]
# doesn't look like it. What if I derive from an instance
# derived from object?
[color=blue][color=green][color=darkred]
>>> class Report(object):[/color][/color][/color]
.... def __getattr__(sel f, name):
.... print "Trying to get", repr(name)
.... raise AttributeError( name)
....[color=blue][color=green][color=darkred]
>>> class Spam(Report()): pass[/color][/color][/color]
....
Traceback (most recent call last):
File "<interacti ve input>", line 1, in ?
TypeError: default __new__ takes no parameters[color=blue][color=green][color=darkred]
>>>[/color][/color][/color]
# Okay.... Don't know what's going on, so I'll
# just fiddle around a bit.
[color=blue][color=green][color=darkred]
>>> class ABCD:[/color][/color][/color]
.... def __init__(self): pass
....[color=blue][color=green][color=darkred]
>>> class Spam(ABCD()): pass[/color][/color][/color]
....
Traceback (most recent call last):
File "<interacti ve input>", line 1, in ?
TypeError: __init__() takes exactly 1 argument (4 given)[color=blue][color=green][color=darkred]
>>> class ABCD:[/color][/color][/color]
.... def __init__(self, a): pass
....[color=blue][color=green][color=darkred]
>>> class Spam(ABCD()): pass[/color][/color][/color]
....
Traceback (most recent call last):
File "<interacti ve input>", line 1, in ?
TypeError: __init__() takes exactly 2 arguments (1 given)[color=blue][color=green][color=darkred]
>>>[/color][/color][/color]
# Which is it; 4 given or 1 given? And
# int had 3 passed to it....
[color=blue][color=green][color=darkred]
>>> class XYZZY:[/color][/color][/color]
.... def __init__(self, **args): print "I have", args
....[color=blue][color=green][color=darkred]
>>> class Spam(XYZZY()): pass[/color][/color][/color]
....
I have {}
Traceback (most recent call last):
File "<interacti ve input>", line 1, in ?
TypeError: __init__() takes exactly 1 argument (4 given)[color=blue][color=green][color=darkred]
>>>[/color][/color][/color]
Comments?
Andrew
dalke@dalkescie ntific.com
Comment