Searching for an easy way to pass in a variable through multiple functions
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 |
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 '18 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 aTypeError
because they are missing the positional argauthstuff
. Also, yourendpoint*()
functions acceptparams
as an arg but don't pass that on torequests_get()
.
– SuperShoot
Nov 20 '18 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 '18 at 17:37
add a comment |
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 '18 at 17:35
xorLogic
asked Nov 19 '18 at 23:23
xorLogicxorLogic
10319
10319
Please explain your downvotes
– xorLogic
Nov 19 '18 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 aTypeError
because they are missing the positional argauthstuff
. Also, yourendpoint*()
functions acceptparams
as an arg but don't pass that on torequests_get()
.
– SuperShoot
Nov 20 '18 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 '18 at 17:37
add a comment |
Please explain your downvotes
– xorLogic
Nov 19 '18 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 aTypeError
because they are missing the positional argauthstuff
. Also, yourendpoint*()
functions acceptparams
as an arg but don't pass that on torequests_get()
.
– SuperShoot
Nov 20 '18 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 '18 at 17:37
Please explain your downvotes
– xorLogic
Nov 19 '18 at 23:41
Please explain your downvotes
– xorLogic
Nov 19 '18 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 '18 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 '18 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 '18 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 '18 at 17:37
add a comment |
1 Answer
1
active
oldest
votes
So, the correct solution for this issue is to use an **arg or **kwarg parameter in your function definitions to pass into sub-functions.
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%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
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
So, the correct solution for this issue is to use an **arg or **kwarg parameter in your function definitions to pass into sub-functions.
add a comment |
So, the correct solution for this issue is to use an **arg or **kwarg parameter in your function definitions to pass into sub-functions.
add a comment |
So, the correct solution for this issue is to use an **arg or **kwarg parameter in your function definitions to pass into sub-functions.
So, the correct solution for this issue is to use an **arg or **kwarg parameter in your function definitions to pass into sub-functions.
edited yesterday
answered Nov 29 '18 at 20:35
xorLogicxorLogic
10319
10319
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%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 '18 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 aTypeError
because they are missing the positional argauthstuff
. Also, yourendpoint*()
functions acceptparams
as an arg but don't pass that on torequests_get()
.– SuperShoot
Nov 20 '18 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 '18 at 17:37