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?










share|improve this question
























  • 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












  • 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















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?










share|improve this question
























  • 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












  • 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













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?










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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


















  • 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












  • 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












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










So, the correct solution for this issue is to use class variables.






share|improve this answer





















    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',
    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
    });


    }
    });














    draft saved

    draft discarded


















    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








    up vote
    0
    down vote



    accepted










    So, the correct solution for this issue is to use class variables.






    share|improve this answer

























      up vote
      0
      down vote



      accepted










      So, the correct solution for this issue is to use class variables.






      share|improve this answer























        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        So, the correct solution for this issue is to use class variables.






        share|improve this answer












        So, the correct solution for this issue is to use class variables.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 29 at 20:35









        xorLogic

        588




        588






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Feedback on college project

            Futebolista

            Albești (Vaslui)