TypeError: super() takes at least 1 argument (0 given) error is specific to any python version?
I'm getting this error
TypeError: super() takes at least 1 argument (0 given)
using this code on python2.7.11:
class Foo(object):
def __init__(self):
pass
class Bar(Foo):
def __init__(self):
super().__init__()
Bar()
The workaround to make it work would be:
class Foo(object):
def __init__(self):
pass
class Bar(Foo):
def __init__(self):
super(Bar, self).__init__()
Bar()
It seems the syntax is specific to python 3. So, what's the best way to provide compatible code between 2.x and 3.x and avoiding this error happening?
python python-2.7 python-2.x
add a comment |
I'm getting this error
TypeError: super() takes at least 1 argument (0 given)
using this code on python2.7.11:
class Foo(object):
def __init__(self):
pass
class Bar(Foo):
def __init__(self):
super().__init__()
Bar()
The workaround to make it work would be:
class Foo(object):
def __init__(self):
pass
class Bar(Foo):
def __init__(self):
super(Bar, self).__init__()
Bar()
It seems the syntax is specific to python 3. So, what's the best way to provide compatible code between 2.x and 3.x and avoiding this error happening?
python python-2.7 python-2.x
1
That syntax is for Python 3.
– Daniel Roseman
Aug 15 '16 at 21:07
@DanielRoseman I see, thanks. To make my question a little bit more useful then I've edited a little bit asking some extra stuff
– BPL
Aug 15 '16 at 21:16
1
The Python 2 syntax is still valid in Python 3 in this case; if you want to support both versions, use that. Note however that there are lots of other incompatibilities between the versions.
– Daniel Roseman
Aug 15 '16 at 21:19
@DanielRoseman Alright, tyvm. All clear then :)
– BPL
Aug 15 '16 at 21:21
add a comment |
I'm getting this error
TypeError: super() takes at least 1 argument (0 given)
using this code on python2.7.11:
class Foo(object):
def __init__(self):
pass
class Bar(Foo):
def __init__(self):
super().__init__()
Bar()
The workaround to make it work would be:
class Foo(object):
def __init__(self):
pass
class Bar(Foo):
def __init__(self):
super(Bar, self).__init__()
Bar()
It seems the syntax is specific to python 3. So, what's the best way to provide compatible code between 2.x and 3.x and avoiding this error happening?
python python-2.7 python-2.x
I'm getting this error
TypeError: super() takes at least 1 argument (0 given)
using this code on python2.7.11:
class Foo(object):
def __init__(self):
pass
class Bar(Foo):
def __init__(self):
super().__init__()
Bar()
The workaround to make it work would be:
class Foo(object):
def __init__(self):
pass
class Bar(Foo):
def __init__(self):
super(Bar, self).__init__()
Bar()
It seems the syntax is specific to python 3. So, what's the best way to provide compatible code between 2.x and 3.x and avoiding this error happening?
python python-2.7 python-2.x
python python-2.7 python-2.x
edited Aug 15 '16 at 21:15
BPL
asked Aug 15 '16 at 21:03
BPLBPL
5,14341855
5,14341855
1
That syntax is for Python 3.
– Daniel Roseman
Aug 15 '16 at 21:07
@DanielRoseman I see, thanks. To make my question a little bit more useful then I've edited a little bit asking some extra stuff
– BPL
Aug 15 '16 at 21:16
1
The Python 2 syntax is still valid in Python 3 in this case; if you want to support both versions, use that. Note however that there are lots of other incompatibilities between the versions.
– Daniel Roseman
Aug 15 '16 at 21:19
@DanielRoseman Alright, tyvm. All clear then :)
– BPL
Aug 15 '16 at 21:21
add a comment |
1
That syntax is for Python 3.
– Daniel Roseman
Aug 15 '16 at 21:07
@DanielRoseman I see, thanks. To make my question a little bit more useful then I've edited a little bit asking some extra stuff
– BPL
Aug 15 '16 at 21:16
1
The Python 2 syntax is still valid in Python 3 in this case; if you want to support both versions, use that. Note however that there are lots of other incompatibilities between the versions.
– Daniel Roseman
Aug 15 '16 at 21:19
@DanielRoseman Alright, tyvm. All clear then :)
– BPL
Aug 15 '16 at 21:21
1
1
That syntax is for Python 3.
– Daniel Roseman
Aug 15 '16 at 21:07
That syntax is for Python 3.
– Daniel Roseman
Aug 15 '16 at 21:07
@DanielRoseman I see, thanks. To make my question a little bit more useful then I've edited a little bit asking some extra stuff
– BPL
Aug 15 '16 at 21:16
@DanielRoseman I see, thanks. To make my question a little bit more useful then I've edited a little bit asking some extra stuff
– BPL
Aug 15 '16 at 21:16
1
1
The Python 2 syntax is still valid in Python 3 in this case; if you want to support both versions, use that. Note however that there are lots of other incompatibilities between the versions.
– Daniel Roseman
Aug 15 '16 at 21:19
The Python 2 syntax is still valid in Python 3 in this case; if you want to support both versions, use that. Note however that there are lots of other incompatibilities between the versions.
– Daniel Roseman
Aug 15 '16 at 21:19
@DanielRoseman Alright, tyvm. All clear then :)
– BPL
Aug 15 '16 at 21:21
@DanielRoseman Alright, tyvm. All clear then :)
– BPL
Aug 15 '16 at 21:21
add a comment |
3 Answers
3
active
oldest
votes
Yes, the 0-argument syntax is specific to Python 3, see What's New in Python 3.0 and PEP 3135 -- New Super.
In Python 2 and code that must be cross-version compatible, just stick to passing in the class object and instance explicitly.
Yes, there are "backports" available that make a no-argument version of super()
work in Python 2 (like the future
library) but these require a number of hacks that include a full scan of the class hierarchy to find a matching function object. This is both fragile and slow, and simply not worth the "convenience".
add a comment |
You can use the future library to have a Python2/Python3 compatibility.
The super function is back-ported.
1
Oh boy, but that implementation. Stack frame inspection and a full traverse of the namespaces of the MRO to find the context? I can't recommend actually using this.
– Martijn Pieters♦
Aug 15 '16 at 22:49
12
Just usesuper(ClassName, self)
and repeat yourself a little.
– Martijn Pieters♦
Aug 15 '16 at 22:50
add a comment |
This is because of version of python. Check your python version with [python --version] it might be 2.7
In 2.7 use this [ super(baseclass, self).__init__() ]
class Bird(object):
def __init__(self):
print("Bird")
def whatIsThis(self):
print("This is bird which can not swim")
class Animal(Bird):
def __init__(self):
super(Bird,self).__init__()
print("Animal")
def whatIsThis(self):
print("THis is animal which can swim")
a1 = Animal()
a1.whatIsThis()
> In 3.0 or more use this [ super().__init__()]
class Bird(object):
def __init__(self):
print("Bird")
def whatIsThis(self):
print("This is bird which can not swim")
class Animal(Bird):
def __init__(self):
super().__init__()
print("Animal")
def whatIsThis(self):
print("THis is animal which can swim")
a1 = Animal()
a1.whatIsThis()
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f38963018%2ftypeerror-super-takes-at-least-1-argument-0-given-error-is-specific-to-any%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Yes, the 0-argument syntax is specific to Python 3, see What's New in Python 3.0 and PEP 3135 -- New Super.
In Python 2 and code that must be cross-version compatible, just stick to passing in the class object and instance explicitly.
Yes, there are "backports" available that make a no-argument version of super()
work in Python 2 (like the future
library) but these require a number of hacks that include a full scan of the class hierarchy to find a matching function object. This is both fragile and slow, and simply not worth the "convenience".
add a comment |
Yes, the 0-argument syntax is specific to Python 3, see What's New in Python 3.0 and PEP 3135 -- New Super.
In Python 2 and code that must be cross-version compatible, just stick to passing in the class object and instance explicitly.
Yes, there are "backports" available that make a no-argument version of super()
work in Python 2 (like the future
library) but these require a number of hacks that include a full scan of the class hierarchy to find a matching function object. This is both fragile and slow, and simply not worth the "convenience".
add a comment |
Yes, the 0-argument syntax is specific to Python 3, see What's New in Python 3.0 and PEP 3135 -- New Super.
In Python 2 and code that must be cross-version compatible, just stick to passing in the class object and instance explicitly.
Yes, there are "backports" available that make a no-argument version of super()
work in Python 2 (like the future
library) but these require a number of hacks that include a full scan of the class hierarchy to find a matching function object. This is both fragile and slow, and simply not worth the "convenience".
Yes, the 0-argument syntax is specific to Python 3, see What's New in Python 3.0 and PEP 3135 -- New Super.
In Python 2 and code that must be cross-version compatible, just stick to passing in the class object and instance explicitly.
Yes, there are "backports" available that make a no-argument version of super()
work in Python 2 (like the future
library) but these require a number of hacks that include a full scan of the class hierarchy to find a matching function object. This is both fragile and slow, and simply not worth the "convenience".
answered Aug 15 '16 at 23:03
Martijn Pieters♦Martijn Pieters
713k13724862303
713k13724862303
add a comment |
add a comment |
You can use the future library to have a Python2/Python3 compatibility.
The super function is back-ported.
1
Oh boy, but that implementation. Stack frame inspection and a full traverse of the namespaces of the MRO to find the context? I can't recommend actually using this.
– Martijn Pieters♦
Aug 15 '16 at 22:49
12
Just usesuper(ClassName, self)
and repeat yourself a little.
– Martijn Pieters♦
Aug 15 '16 at 22:50
add a comment |
You can use the future library to have a Python2/Python3 compatibility.
The super function is back-ported.
1
Oh boy, but that implementation. Stack frame inspection and a full traverse of the namespaces of the MRO to find the context? I can't recommend actually using this.
– Martijn Pieters♦
Aug 15 '16 at 22:49
12
Just usesuper(ClassName, self)
and repeat yourself a little.
– Martijn Pieters♦
Aug 15 '16 at 22:50
add a comment |
You can use the future library to have a Python2/Python3 compatibility.
The super function is back-ported.
You can use the future library to have a Python2/Python3 compatibility.
The super function is back-ported.
answered Aug 15 '16 at 21:35
Laurent LAPORTELaurent LAPORTE
11.2k22957
11.2k22957
1
Oh boy, but that implementation. Stack frame inspection and a full traverse of the namespaces of the MRO to find the context? I can't recommend actually using this.
– Martijn Pieters♦
Aug 15 '16 at 22:49
12
Just usesuper(ClassName, self)
and repeat yourself a little.
– Martijn Pieters♦
Aug 15 '16 at 22:50
add a comment |
1
Oh boy, but that implementation. Stack frame inspection and a full traverse of the namespaces of the MRO to find the context? I can't recommend actually using this.
– Martijn Pieters♦
Aug 15 '16 at 22:49
12
Just usesuper(ClassName, self)
and repeat yourself a little.
– Martijn Pieters♦
Aug 15 '16 at 22:50
1
1
Oh boy, but that implementation. Stack frame inspection and a full traverse of the namespaces of the MRO to find the context? I can't recommend actually using this.
– Martijn Pieters♦
Aug 15 '16 at 22:49
Oh boy, but that implementation. Stack frame inspection and a full traverse of the namespaces of the MRO to find the context? I can't recommend actually using this.
– Martijn Pieters♦
Aug 15 '16 at 22:49
12
12
Just use
super(ClassName, self)
and repeat yourself a little.– Martijn Pieters♦
Aug 15 '16 at 22:50
Just use
super(ClassName, self)
and repeat yourself a little.– Martijn Pieters♦
Aug 15 '16 at 22:50
add a comment |
This is because of version of python. Check your python version with [python --version] it might be 2.7
In 2.7 use this [ super(baseclass, self).__init__() ]
class Bird(object):
def __init__(self):
print("Bird")
def whatIsThis(self):
print("This is bird which can not swim")
class Animal(Bird):
def __init__(self):
super(Bird,self).__init__()
print("Animal")
def whatIsThis(self):
print("THis is animal which can swim")
a1 = Animal()
a1.whatIsThis()
> In 3.0 or more use this [ super().__init__()]
class Bird(object):
def __init__(self):
print("Bird")
def whatIsThis(self):
print("This is bird which can not swim")
class Animal(Bird):
def __init__(self):
super().__init__()
print("Animal")
def whatIsThis(self):
print("THis is animal which can swim")
a1 = Animal()
a1.whatIsThis()
add a comment |
This is because of version of python. Check your python version with [python --version] it might be 2.7
In 2.7 use this [ super(baseclass, self).__init__() ]
class Bird(object):
def __init__(self):
print("Bird")
def whatIsThis(self):
print("This is bird which can not swim")
class Animal(Bird):
def __init__(self):
super(Bird,self).__init__()
print("Animal")
def whatIsThis(self):
print("THis is animal which can swim")
a1 = Animal()
a1.whatIsThis()
> In 3.0 or more use this [ super().__init__()]
class Bird(object):
def __init__(self):
print("Bird")
def whatIsThis(self):
print("This is bird which can not swim")
class Animal(Bird):
def __init__(self):
super().__init__()
print("Animal")
def whatIsThis(self):
print("THis is animal which can swim")
a1 = Animal()
a1.whatIsThis()
add a comment |
This is because of version of python. Check your python version with [python --version] it might be 2.7
In 2.7 use this [ super(baseclass, self).__init__() ]
class Bird(object):
def __init__(self):
print("Bird")
def whatIsThis(self):
print("This is bird which can not swim")
class Animal(Bird):
def __init__(self):
super(Bird,self).__init__()
print("Animal")
def whatIsThis(self):
print("THis is animal which can swim")
a1 = Animal()
a1.whatIsThis()
> In 3.0 or more use this [ super().__init__()]
class Bird(object):
def __init__(self):
print("Bird")
def whatIsThis(self):
print("This is bird which can not swim")
class Animal(Bird):
def __init__(self):
super().__init__()
print("Animal")
def whatIsThis(self):
print("THis is animal which can swim")
a1 = Animal()
a1.whatIsThis()
This is because of version of python. Check your python version with [python --version] it might be 2.7
In 2.7 use this [ super(baseclass, self).__init__() ]
class Bird(object):
def __init__(self):
print("Bird")
def whatIsThis(self):
print("This is bird which can not swim")
class Animal(Bird):
def __init__(self):
super(Bird,self).__init__()
print("Animal")
def whatIsThis(self):
print("THis is animal which can swim")
a1 = Animal()
a1.whatIsThis()
> In 3.0 or more use this [ super().__init__()]
class Bird(object):
def __init__(self):
print("Bird")
def whatIsThis(self):
print("This is bird which can not swim")
class Animal(Bird):
def __init__(self):
super().__init__()
print("Animal")
def whatIsThis(self):
print("THis is animal which can swim")
a1 = Animal()
a1.whatIsThis()
answered Nov 14 '18 at 16:57
Viraj.HadoopViraj.Hadoop
2559
2559
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f38963018%2ftypeerror-super-takes-at-least-1-argument-0-given-error-is-specific-to-any%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
That syntax is for Python 3.
– Daniel Roseman
Aug 15 '16 at 21:07
@DanielRoseman I see, thanks. To make my question a little bit more useful then I've edited a little bit asking some extra stuff
– BPL
Aug 15 '16 at 21:16
1
The Python 2 syntax is still valid in Python 3 in this case; if you want to support both versions, use that. Note however that there are lots of other incompatibilities between the versions.
– Daniel Roseman
Aug 15 '16 at 21:19
@DanielRoseman Alright, tyvm. All clear then :)
– BPL
Aug 15 '16 at 21:21