How do i solve“ missing 1 required positional argument ”
I wrote a method in class and got the following error
yearLinks = link(root_url + '/oilmarketreport/reports/')
TypeError: link() missing 1 required positional argument: 'url'
My code is:-
class Data:
def __init__(self):
try: ------
----
else:
def link(self, url):
all_links =
page = requests.get(url)
soup = BeautifulSoup(page.text, 'html.parser')
for href in soup.find_all(class_='omrlist'):
all_links.append(root_url + href.find('a').get('href'))
return all_links
yearLinks = link(root_url + '/oilmarketreport/reports/')
reportLinks =
for url in yearLinks:
links = link(url)
So how i solve this in python.
python methods typeerror
|
show 2 more comments
I wrote a method in class and got the following error
yearLinks = link(root_url + '/oilmarketreport/reports/')
TypeError: link() missing 1 required positional argument: 'url'
My code is:-
class Data:
def __init__(self):
try: ------
----
else:
def link(self, url):
all_links =
page = requests.get(url)
soup = BeautifulSoup(page.text, 'html.parser')
for href in soup.find_all(class_='omrlist'):
all_links.append(root_url + href.find('a').get('href'))
return all_links
yearLinks = link(root_url + '/oilmarketreport/reports/')
reportLinks =
for url in yearLinks:
links = link(url)
So how i solve this in python.
python methods typeerror
What islinks
?
– Loocid
Nov 23 '18 at 5:58
You needs to useself.links(url)
orself.link(url)
depending on what named your method.
– Red Cricket
Nov 23 '18 at 5:59
3
the indentation is not clear.
– b-fg
Nov 23 '18 at 6:00
links is variable having all links which we need
– royal
Nov 23 '18 at 6:03
@ Red Cricket, links is variable name and link is method name
– royal
Nov 23 '18 at 6:06
|
show 2 more comments
I wrote a method in class and got the following error
yearLinks = link(root_url + '/oilmarketreport/reports/')
TypeError: link() missing 1 required positional argument: 'url'
My code is:-
class Data:
def __init__(self):
try: ------
----
else:
def link(self, url):
all_links =
page = requests.get(url)
soup = BeautifulSoup(page.text, 'html.parser')
for href in soup.find_all(class_='omrlist'):
all_links.append(root_url + href.find('a').get('href'))
return all_links
yearLinks = link(root_url + '/oilmarketreport/reports/')
reportLinks =
for url in yearLinks:
links = link(url)
So how i solve this in python.
python methods typeerror
I wrote a method in class and got the following error
yearLinks = link(root_url + '/oilmarketreport/reports/')
TypeError: link() missing 1 required positional argument: 'url'
My code is:-
class Data:
def __init__(self):
try: ------
----
else:
def link(self, url):
all_links =
page = requests.get(url)
soup = BeautifulSoup(page.text, 'html.parser')
for href in soup.find_all(class_='omrlist'):
all_links.append(root_url + href.find('a').get('href'))
return all_links
yearLinks = link(root_url + '/oilmarketreport/reports/')
reportLinks =
for url in yearLinks:
links = link(url)
So how i solve this in python.
python methods typeerror
python methods typeerror
edited Nov 23 '18 at 6:39
royal
asked Nov 23 '18 at 5:56
royalroyal
229
229
What islinks
?
– Loocid
Nov 23 '18 at 5:58
You needs to useself.links(url)
orself.link(url)
depending on what named your method.
– Red Cricket
Nov 23 '18 at 5:59
3
the indentation is not clear.
– b-fg
Nov 23 '18 at 6:00
links is variable having all links which we need
– royal
Nov 23 '18 at 6:03
@ Red Cricket, links is variable name and link is method name
– royal
Nov 23 '18 at 6:06
|
show 2 more comments
What islinks
?
– Loocid
Nov 23 '18 at 5:58
You needs to useself.links(url)
orself.link(url)
depending on what named your method.
– Red Cricket
Nov 23 '18 at 5:59
3
the indentation is not clear.
– b-fg
Nov 23 '18 at 6:00
links is variable having all links which we need
– royal
Nov 23 '18 at 6:03
@ Red Cricket, links is variable name and link is method name
– royal
Nov 23 '18 at 6:06
What is
links
?– Loocid
Nov 23 '18 at 5:58
What is
links
?– Loocid
Nov 23 '18 at 5:58
You needs to use
self.links(url)
or self.link(url)
depending on what named your method.– Red Cricket
Nov 23 '18 at 5:59
You needs to use
self.links(url)
or self.link(url)
depending on what named your method.– Red Cricket
Nov 23 '18 at 5:59
3
3
the indentation is not clear.
– b-fg
Nov 23 '18 at 6:00
the indentation is not clear.
– b-fg
Nov 23 '18 at 6:00
links is variable having all links which we need
– royal
Nov 23 '18 at 6:03
links is variable having all links which we need
– royal
Nov 23 '18 at 6:03
@ Red Cricket, links is variable name and link is method name
– royal
Nov 23 '18 at 6:06
@ Red Cricket, links is variable name and link is method name
– royal
Nov 23 '18 at 6:06
|
show 2 more comments
3 Answers
3
active
oldest
votes
you have to do self.link(url)
. Its missing the self parameter.
Edit:
you can update the line as:
yearLinks = self.link(root_url + '/oilmarketreport/reports/')
No sir. error is comming in the yearLinks veriable. yearlinks veriable is not in any method
– royal
Nov 23 '18 at 6:50
updated the answer
– Omair Shamshir
Nov 23 '18 at 7:02
Sir prob is not solve yet please guide. need to integrate my code to other code So..
– royal
Nov 23 '18 at 7:30
I think the indentation of the code in your question doesn't match your real code. Until you fix that, we won't be able to help.
– Matthias
Nov 23 '18 at 8:40
add a comment |
it's an unclear question. maybe staticmethod is what you wanted.
class Data:
def __init__(self):
try: ------
----
else:
@staticmethod
def link(url):
all_links =
page = requests.get(url)
soup = BeautifulSoup(page.text, 'html.parser')
for href in soup.find_all(class_='omrlist'):
all_links.append(root_url + href.find('a').get('href'))
return all_links
yearLinks = Data.link(root_url + '/oilmarketreport/reports/')
reportLinks =
for url in yearLinks:
links = Data.link(url)
yearLinks = Data.link(root_url + '/oilmarketreport/reports/') NameError: name 'Data' is not defined
– royal
Nov 23 '18 at 9:00
I need to integrate my to to other code So need to put all code in class and method format. during that got above error
– royal
Nov 23 '18 at 9:03
@royal can you check the indention? that's weird. you put code in a class.
– Kevin Chan
Nov 24 '18 at 13:24
add a comment |
Just for clearness:
class Data:
def __init__(self):
""""""
@staticmethod
def link(url):
return url
print(Data.link("some_link")) # call method of class Data (will print "some_link")
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%2f53441308%2fhow-do-i-solve-missing-1-required-positional-argument%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
you have to do self.link(url)
. Its missing the self parameter.
Edit:
you can update the line as:
yearLinks = self.link(root_url + '/oilmarketreport/reports/')
No sir. error is comming in the yearLinks veriable. yearlinks veriable is not in any method
– royal
Nov 23 '18 at 6:50
updated the answer
– Omair Shamshir
Nov 23 '18 at 7:02
Sir prob is not solve yet please guide. need to integrate my code to other code So..
– royal
Nov 23 '18 at 7:30
I think the indentation of the code in your question doesn't match your real code. Until you fix that, we won't be able to help.
– Matthias
Nov 23 '18 at 8:40
add a comment |
you have to do self.link(url)
. Its missing the self parameter.
Edit:
you can update the line as:
yearLinks = self.link(root_url + '/oilmarketreport/reports/')
No sir. error is comming in the yearLinks veriable. yearlinks veriable is not in any method
– royal
Nov 23 '18 at 6:50
updated the answer
– Omair Shamshir
Nov 23 '18 at 7:02
Sir prob is not solve yet please guide. need to integrate my code to other code So..
– royal
Nov 23 '18 at 7:30
I think the indentation of the code in your question doesn't match your real code. Until you fix that, we won't be able to help.
– Matthias
Nov 23 '18 at 8:40
add a comment |
you have to do self.link(url)
. Its missing the self parameter.
Edit:
you can update the line as:
yearLinks = self.link(root_url + '/oilmarketreport/reports/')
you have to do self.link(url)
. Its missing the self parameter.
Edit:
you can update the line as:
yearLinks = self.link(root_url + '/oilmarketreport/reports/')
edited Nov 23 '18 at 7:02
answered Nov 23 '18 at 6:42
Omair ShamshirOmair Shamshir
1,734821
1,734821
No sir. error is comming in the yearLinks veriable. yearlinks veriable is not in any method
– royal
Nov 23 '18 at 6:50
updated the answer
– Omair Shamshir
Nov 23 '18 at 7:02
Sir prob is not solve yet please guide. need to integrate my code to other code So..
– royal
Nov 23 '18 at 7:30
I think the indentation of the code in your question doesn't match your real code. Until you fix that, we won't be able to help.
– Matthias
Nov 23 '18 at 8:40
add a comment |
No sir. error is comming in the yearLinks veriable. yearlinks veriable is not in any method
– royal
Nov 23 '18 at 6:50
updated the answer
– Omair Shamshir
Nov 23 '18 at 7:02
Sir prob is not solve yet please guide. need to integrate my code to other code So..
– royal
Nov 23 '18 at 7:30
I think the indentation of the code in your question doesn't match your real code. Until you fix that, we won't be able to help.
– Matthias
Nov 23 '18 at 8:40
No sir. error is comming in the yearLinks veriable. yearlinks veriable is not in any method
– royal
Nov 23 '18 at 6:50
No sir. error is comming in the yearLinks veriable. yearlinks veriable is not in any method
– royal
Nov 23 '18 at 6:50
updated the answer
– Omair Shamshir
Nov 23 '18 at 7:02
updated the answer
– Omair Shamshir
Nov 23 '18 at 7:02
Sir prob is not solve yet please guide. need to integrate my code to other code So..
– royal
Nov 23 '18 at 7:30
Sir prob is not solve yet please guide. need to integrate my code to other code So..
– royal
Nov 23 '18 at 7:30
I think the indentation of the code in your question doesn't match your real code. Until you fix that, we won't be able to help.
– Matthias
Nov 23 '18 at 8:40
I think the indentation of the code in your question doesn't match your real code. Until you fix that, we won't be able to help.
– Matthias
Nov 23 '18 at 8:40
add a comment |
it's an unclear question. maybe staticmethod is what you wanted.
class Data:
def __init__(self):
try: ------
----
else:
@staticmethod
def link(url):
all_links =
page = requests.get(url)
soup = BeautifulSoup(page.text, 'html.parser')
for href in soup.find_all(class_='omrlist'):
all_links.append(root_url + href.find('a').get('href'))
return all_links
yearLinks = Data.link(root_url + '/oilmarketreport/reports/')
reportLinks =
for url in yearLinks:
links = Data.link(url)
yearLinks = Data.link(root_url + '/oilmarketreport/reports/') NameError: name 'Data' is not defined
– royal
Nov 23 '18 at 9:00
I need to integrate my to to other code So need to put all code in class and method format. during that got above error
– royal
Nov 23 '18 at 9:03
@royal can you check the indention? that's weird. you put code in a class.
– Kevin Chan
Nov 24 '18 at 13:24
add a comment |
it's an unclear question. maybe staticmethod is what you wanted.
class Data:
def __init__(self):
try: ------
----
else:
@staticmethod
def link(url):
all_links =
page = requests.get(url)
soup = BeautifulSoup(page.text, 'html.parser')
for href in soup.find_all(class_='omrlist'):
all_links.append(root_url + href.find('a').get('href'))
return all_links
yearLinks = Data.link(root_url + '/oilmarketreport/reports/')
reportLinks =
for url in yearLinks:
links = Data.link(url)
yearLinks = Data.link(root_url + '/oilmarketreport/reports/') NameError: name 'Data' is not defined
– royal
Nov 23 '18 at 9:00
I need to integrate my to to other code So need to put all code in class and method format. during that got above error
– royal
Nov 23 '18 at 9:03
@royal can you check the indention? that's weird. you put code in a class.
– Kevin Chan
Nov 24 '18 at 13:24
add a comment |
it's an unclear question. maybe staticmethod is what you wanted.
class Data:
def __init__(self):
try: ------
----
else:
@staticmethod
def link(url):
all_links =
page = requests.get(url)
soup = BeautifulSoup(page.text, 'html.parser')
for href in soup.find_all(class_='omrlist'):
all_links.append(root_url + href.find('a').get('href'))
return all_links
yearLinks = Data.link(root_url + '/oilmarketreport/reports/')
reportLinks =
for url in yearLinks:
links = Data.link(url)
it's an unclear question. maybe staticmethod is what you wanted.
class Data:
def __init__(self):
try: ------
----
else:
@staticmethod
def link(url):
all_links =
page = requests.get(url)
soup = BeautifulSoup(page.text, 'html.parser')
for href in soup.find_all(class_='omrlist'):
all_links.append(root_url + href.find('a').get('href'))
return all_links
yearLinks = Data.link(root_url + '/oilmarketreport/reports/')
reportLinks =
for url in yearLinks:
links = Data.link(url)
answered Nov 23 '18 at 8:50
Kevin ChanKevin Chan
192
192
yearLinks = Data.link(root_url + '/oilmarketreport/reports/') NameError: name 'Data' is not defined
– royal
Nov 23 '18 at 9:00
I need to integrate my to to other code So need to put all code in class and method format. during that got above error
– royal
Nov 23 '18 at 9:03
@royal can you check the indention? that's weird. you put code in a class.
– Kevin Chan
Nov 24 '18 at 13:24
add a comment |
yearLinks = Data.link(root_url + '/oilmarketreport/reports/') NameError: name 'Data' is not defined
– royal
Nov 23 '18 at 9:00
I need to integrate my to to other code So need to put all code in class and method format. during that got above error
– royal
Nov 23 '18 at 9:03
@royal can you check the indention? that's weird. you put code in a class.
– Kevin Chan
Nov 24 '18 at 13:24
yearLinks = Data.link(root_url + '/oilmarketreport/reports/') NameError: name 'Data' is not defined
– royal
Nov 23 '18 at 9:00
yearLinks = Data.link(root_url + '/oilmarketreport/reports/') NameError: name 'Data' is not defined
– royal
Nov 23 '18 at 9:00
I need to integrate my to to other code So need to put all code in class and method format. during that got above error
– royal
Nov 23 '18 at 9:03
I need to integrate my to to other code So need to put all code in class and method format. during that got above error
– royal
Nov 23 '18 at 9:03
@royal can you check the indention? that's weird. you put code in a class.
– Kevin Chan
Nov 24 '18 at 13:24
@royal can you check the indention? that's weird. you put code in a class.
– Kevin Chan
Nov 24 '18 at 13:24
add a comment |
Just for clearness:
class Data:
def __init__(self):
""""""
@staticmethod
def link(url):
return url
print(Data.link("some_link")) # call method of class Data (will print "some_link")
add a comment |
Just for clearness:
class Data:
def __init__(self):
""""""
@staticmethod
def link(url):
return url
print(Data.link("some_link")) # call method of class Data (will print "some_link")
add a comment |
Just for clearness:
class Data:
def __init__(self):
""""""
@staticmethod
def link(url):
return url
print(Data.link("some_link")) # call method of class Data (will print "some_link")
Just for clearness:
class Data:
def __init__(self):
""""""
@staticmethod
def link(url):
return url
print(Data.link("some_link")) # call method of class Data (will print "some_link")
answered Nov 23 '18 at 9:17
Andrey SuglobovAndrey Suglobov
1549
1549
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%2f53441308%2fhow-do-i-solve-missing-1-required-positional-argument%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
What is
links
?– Loocid
Nov 23 '18 at 5:58
You needs to use
self.links(url)
orself.link(url)
depending on what named your method.– Red Cricket
Nov 23 '18 at 5:59
3
the indentation is not clear.
– b-fg
Nov 23 '18 at 6:00
links is variable having all links which we need
– royal
Nov 23 '18 at 6:03
@ Red Cricket, links is variable name and link is method name
– royal
Nov 23 '18 at 6:06