Searching for an easy way to pass in a variable through multiple functions
up vote
0
down vote
favorite
I'm searching for an efficient way to pass input for the 'params' parameter into my python requests call for individual GET requests and I'm not sure if my approach would be overly complicated:
What I have now:
main.py
#Example1
module.endpoint1()
module.py
import requests
def requests_get(url, authstuff, params=None):
request=(requests.get(url, params=params, authstuff)
def endpoint1():
url=...
return requests_get(url)
def endpoint2():
url=...
return requests_get(url)
def endpoint3():
url=...
return requests_get(url)
.....
What I will have once I make the 'params' parameter accessible in my main.py call:
main.py
#Example1
module.endpoint1(params=?functioncode)
module.py
import requests
def requests_get(url, authstuff, params=None):
request=(requests.get(url, params=params, authstuff)
def endpoint1(params=None):
url=...
return requests_get(url, params)
def endpoint2(params=None):
url=...
return requests_get(url, params)
def endpoint3(params=None):
url=...
return requests_get(url, params)
.....
I'm not sure if this is an efficient means or if there is another route to take that would be simpler to access the secondary function call to 'requests_get'. I'd hate to have to specify the 'params=None' setting for each endpoint function because I have hundreds but would this pretty much be the only way to do it?
python-3.x python-requests
add a comment |
up vote
0
down vote
favorite
I'm searching for an efficient way to pass input for the 'params' parameter into my python requests call for individual GET requests and I'm not sure if my approach would be overly complicated:
What I have now:
main.py
#Example1
module.endpoint1()
module.py
import requests
def requests_get(url, authstuff, params=None):
request=(requests.get(url, params=params, authstuff)
def endpoint1():
url=...
return requests_get(url)
def endpoint2():
url=...
return requests_get(url)
def endpoint3():
url=...
return requests_get(url)
.....
What I will have once I make the 'params' parameter accessible in my main.py call:
main.py
#Example1
module.endpoint1(params=?functioncode)
module.py
import requests
def requests_get(url, authstuff, params=None):
request=(requests.get(url, params=params, authstuff)
def endpoint1(params=None):
url=...
return requests_get(url, params)
def endpoint2(params=None):
url=...
return requests_get(url, params)
def endpoint3(params=None):
url=...
return requests_get(url, params)
.....
I'm not sure if this is an efficient means or if there is another route to take that would be simpler to access the secondary function call to 'requests_get'. I'd hate to have to specify the 'params=None' setting for each endpoint function because I have hundreds but would this pretty much be the only way to do it?
python-3.x python-requests
Please explain your downvotes
– xorLogic
Nov 19 at 23:41
I didn't downvote you but I can understand why you have been. It is pretty hard to deduce what you are trying to do from the question and your example is not Minimal, Complete or Verifiable. For example,requests_get()defined a positional arg after a keyword arg which is aSyntaxError. Fix that and then every one of yourendpoint*()functions will raise aTypeErrorbecause they are missing the positional argauthstuff. Also, yourendpoint*()functions acceptparamsas an arg but don't pass that on torequests_get().
– SuperShoot
Nov 20 at 0:15
Okay, so I corrected my function args and the variables passed to my second arg. My question though is whether I constructed an efficient way to pass my main params variable two functions deep to get it passed into my "requests.get" callout.
– xorLogic
Nov 20 at 17:37
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm searching for an efficient way to pass input for the 'params' parameter into my python requests call for individual GET requests and I'm not sure if my approach would be overly complicated:
What I have now:
main.py
#Example1
module.endpoint1()
module.py
import requests
def requests_get(url, authstuff, params=None):
request=(requests.get(url, params=params, authstuff)
def endpoint1():
url=...
return requests_get(url)
def endpoint2():
url=...
return requests_get(url)
def endpoint3():
url=...
return requests_get(url)
.....
What I will have once I make the 'params' parameter accessible in my main.py call:
main.py
#Example1
module.endpoint1(params=?functioncode)
module.py
import requests
def requests_get(url, authstuff, params=None):
request=(requests.get(url, params=params, authstuff)
def endpoint1(params=None):
url=...
return requests_get(url, params)
def endpoint2(params=None):
url=...
return requests_get(url, params)
def endpoint3(params=None):
url=...
return requests_get(url, params)
.....
I'm not sure if this is an efficient means or if there is another route to take that would be simpler to access the secondary function call to 'requests_get'. I'd hate to have to specify the 'params=None' setting for each endpoint function because I have hundreds but would this pretty much be the only way to do it?
python-3.x python-requests
I'm searching for an efficient way to pass input for the 'params' parameter into my python requests call for individual GET requests and I'm not sure if my approach would be overly complicated:
What I have now:
main.py
#Example1
module.endpoint1()
module.py
import requests
def requests_get(url, authstuff, params=None):
request=(requests.get(url, params=params, authstuff)
def endpoint1():
url=...
return requests_get(url)
def endpoint2():
url=...
return requests_get(url)
def endpoint3():
url=...
return requests_get(url)
.....
What I will have once I make the 'params' parameter accessible in my main.py call:
main.py
#Example1
module.endpoint1(params=?functioncode)
module.py
import requests
def requests_get(url, authstuff, params=None):
request=(requests.get(url, params=params, authstuff)
def endpoint1(params=None):
url=...
return requests_get(url, params)
def endpoint2(params=None):
url=...
return requests_get(url, params)
def endpoint3(params=None):
url=...
return requests_get(url, params)
.....
I'm not sure if this is an efficient means or if there is another route to take that would be simpler to access the secondary function call to 'requests_get'. I'd hate to have to specify the 'params=None' setting for each endpoint function because I have hundreds but would this pretty much be the only way to do it?
python-3.x python-requests
python-3.x python-requests
edited Nov 20 at 17:35
asked Nov 19 at 23:23
xorLogic
588
588
Please explain your downvotes
– xorLogic
Nov 19 at 23:41
I didn't downvote you but I can understand why you have been. It is pretty hard to deduce what you are trying to do from the question and your example is not Minimal, Complete or Verifiable. For example,requests_get()defined a positional arg after a keyword arg which is aSyntaxError. Fix that and then every one of yourendpoint*()functions will raise aTypeErrorbecause they are missing the positional argauthstuff. Also, yourendpoint*()functions acceptparamsas an arg but don't pass that on torequests_get().
– SuperShoot
Nov 20 at 0:15
Okay, so I corrected my function args and the variables passed to my second arg. My question though is whether I constructed an efficient way to pass my main params variable two functions deep to get it passed into my "requests.get" callout.
– xorLogic
Nov 20 at 17:37
add a comment |
Please explain your downvotes
– xorLogic
Nov 19 at 23:41
I didn't downvote you but I can understand why you have been. It is pretty hard to deduce what you are trying to do from the question and your example is not Minimal, Complete or Verifiable. For example,requests_get()defined a positional arg after a keyword arg which is aSyntaxError. Fix that and then every one of yourendpoint*()functions will raise aTypeErrorbecause they are missing the positional argauthstuff. Also, yourendpoint*()functions acceptparamsas an arg but don't pass that on torequests_get().
– SuperShoot
Nov 20 at 0:15
Okay, so I corrected my function args and the variables passed to my second arg. My question though is whether I constructed an efficient way to pass my main params variable two functions deep to get it passed into my "requests.get" callout.
– xorLogic
Nov 20 at 17:37
Please explain your downvotes
– xorLogic
Nov 19 at 23:41
Please explain your downvotes
– xorLogic
Nov 19 at 23:41
I didn't downvote you but I can understand why you have been. It is pretty hard to deduce what you are trying to do from the question and your example is not Minimal, Complete or Verifiable. For example,
requests_get() defined a positional arg after a keyword arg which is a SyntaxError. Fix that and then every one of your endpoint*() functions will raise a TypeError because they are missing the positional arg authstuff. Also, your endpoint*() functions accept params as an arg but don't pass that on to requests_get().– SuperShoot
Nov 20 at 0:15
I didn't downvote you but I can understand why you have been. It is pretty hard to deduce what you are trying to do from the question and your example is not Minimal, Complete or Verifiable. For example,
requests_get() defined a positional arg after a keyword arg which is a SyntaxError. Fix that and then every one of your endpoint*() functions will raise a TypeError because they are missing the positional arg authstuff. Also, your endpoint*() functions accept params as an arg but don't pass that on to requests_get().– SuperShoot
Nov 20 at 0:15
Okay, so I corrected my function args and the variables passed to my second arg. My question though is whether I constructed an efficient way to pass my main params variable two functions deep to get it passed into my "requests.get" callout.
– xorLogic
Nov 20 at 17:37
Okay, so I corrected my function args and the variables passed to my second arg. My question though is whether I constructed an efficient way to pass my main params variable two functions deep to get it passed into my "requests.get" callout.
– xorLogic
Nov 20 at 17:37
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
So, the correct solution for this issue is to use class variables.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
So, the correct solution for this issue is to use class variables.
add a comment |
up vote
0
down vote
accepted
So, the correct solution for this issue is to use class variables.
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
So, the correct solution for this issue is to use class variables.
So, the correct solution for this issue is to use class variables.
answered Nov 29 at 20:35
xorLogic
588
588
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53384084%2fsearching-for-an-easy-way-to-pass-in-a-variable-through-multiple-functions%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
Please explain your downvotes
– xorLogic
Nov 19 at 23:41
I didn't downvote you but I can understand why you have been. It is pretty hard to deduce what you are trying to do from the question and your example is not Minimal, Complete or Verifiable. For example,
requests_get()defined a positional arg after a keyword arg which is aSyntaxError. Fix that and then every one of yourendpoint*()functions will raise aTypeErrorbecause they are missing the positional argauthstuff. Also, yourendpoint*()functions acceptparamsas an arg but don't pass that on torequests_get().– SuperShoot
Nov 20 at 0:15
Okay, so I corrected my function args and the variables passed to my second arg. My question though is whether I constructed an efficient way to pass my main params variable two functions deep to get it passed into my "requests.get" callout.
– xorLogic
Nov 20 at 17:37