Accepting user input for Argparse arguments












0















How would I go about defining the float value of each argument with a user prompt? Currently I'm using default = x, but would rather allow a user to define a few variables before collecting them together and passing them to a function.



I thought I could do something like:



first = input("first float") 
second = input("second float")
third = input("third float")


...but I get: TypeError("unsupported operand type(s) for *=: 'float' and 'NoneType'",)



Here's code that works fine, but uses default = x vs. user prompt.



import sys
import argparse

if __name__ == "__main__":
args = sys.argv
args.pop(0)
arg_parser = argparse.ArgumentParser("Help")

arg_parser.add_argument("--first", type=float, help="first value", default=1)
arg_parser.add_argument("--second", type=float, help="second value", default=2)
arg_parser.add_argument("--third", type=float, help="third value", default=3)
args = arg_parser.parse_args(args)
whatever = WhateverWhatever(args.first, args.second, args.third)
whatever.start()

class WhateverWhatever:
def __init__(self, first = 1, second = 2, third = 3):
self.first = first
self.second = second
self.third = third









share|improve this question




















  • 3





    I don't understand. Can you give an example of what you want?

    – John Kugelman
    Nov 19 '18 at 18:16











  • You have a typo- args.three instead of args.third under whatever =. Beyond that, I agree with John Kugelman. You seem to already have what you want.

    – John Rouhana
    Nov 19 '18 at 18:20













  • How are you running this script? On what system, or with what shell? Normally we just use python myscript.py --first 3 --second 33 --third 43. Do you understnd what we mean by commandline arguments?

    – hpaulj
    Nov 19 '18 at 18:45











  • @JohnKugelman The above code defines the floats with default = x, I'd rather have a user prompt. Normally I'd just throw in something like first = input("first float") second = input("second float") ...but I get: TypeError("unsupported operand type(s) for *=: 'float' and 'NoneType'",)

    – delphifissure
    Nov 19 '18 at 19:31


















0















How would I go about defining the float value of each argument with a user prompt? Currently I'm using default = x, but would rather allow a user to define a few variables before collecting them together and passing them to a function.



I thought I could do something like:



first = input("first float") 
second = input("second float")
third = input("third float")


...but I get: TypeError("unsupported operand type(s) for *=: 'float' and 'NoneType'",)



Here's code that works fine, but uses default = x vs. user prompt.



import sys
import argparse

if __name__ == "__main__":
args = sys.argv
args.pop(0)
arg_parser = argparse.ArgumentParser("Help")

arg_parser.add_argument("--first", type=float, help="first value", default=1)
arg_parser.add_argument("--second", type=float, help="second value", default=2)
arg_parser.add_argument("--third", type=float, help="third value", default=3)
args = arg_parser.parse_args(args)
whatever = WhateverWhatever(args.first, args.second, args.third)
whatever.start()

class WhateverWhatever:
def __init__(self, first = 1, second = 2, third = 3):
self.first = first
self.second = second
self.third = third









share|improve this question




















  • 3





    I don't understand. Can you give an example of what you want?

    – John Kugelman
    Nov 19 '18 at 18:16











  • You have a typo- args.three instead of args.third under whatever =. Beyond that, I agree with John Kugelman. You seem to already have what you want.

    – John Rouhana
    Nov 19 '18 at 18:20













  • How are you running this script? On what system, or with what shell? Normally we just use python myscript.py --first 3 --second 33 --third 43. Do you understnd what we mean by commandline arguments?

    – hpaulj
    Nov 19 '18 at 18:45











  • @JohnKugelman The above code defines the floats with default = x, I'd rather have a user prompt. Normally I'd just throw in something like first = input("first float") second = input("second float") ...but I get: TypeError("unsupported operand type(s) for *=: 'float' and 'NoneType'",)

    – delphifissure
    Nov 19 '18 at 19:31
















0












0








0








How would I go about defining the float value of each argument with a user prompt? Currently I'm using default = x, but would rather allow a user to define a few variables before collecting them together and passing them to a function.



I thought I could do something like:



first = input("first float") 
second = input("second float")
third = input("third float")


...but I get: TypeError("unsupported operand type(s) for *=: 'float' and 'NoneType'",)



Here's code that works fine, but uses default = x vs. user prompt.



import sys
import argparse

if __name__ == "__main__":
args = sys.argv
args.pop(0)
arg_parser = argparse.ArgumentParser("Help")

arg_parser.add_argument("--first", type=float, help="first value", default=1)
arg_parser.add_argument("--second", type=float, help="second value", default=2)
arg_parser.add_argument("--third", type=float, help="third value", default=3)
args = arg_parser.parse_args(args)
whatever = WhateverWhatever(args.first, args.second, args.third)
whatever.start()

class WhateverWhatever:
def __init__(self, first = 1, second = 2, third = 3):
self.first = first
self.second = second
self.third = third









share|improve this question
















How would I go about defining the float value of each argument with a user prompt? Currently I'm using default = x, but would rather allow a user to define a few variables before collecting them together and passing them to a function.



I thought I could do something like:



first = input("first float") 
second = input("second float")
third = input("third float")


...but I get: TypeError("unsupported operand type(s) for *=: 'float' and 'NoneType'",)



Here's code that works fine, but uses default = x vs. user prompt.



import sys
import argparse

if __name__ == "__main__":
args = sys.argv
args.pop(0)
arg_parser = argparse.ArgumentParser("Help")

arg_parser.add_argument("--first", type=float, help="first value", default=1)
arg_parser.add_argument("--second", type=float, help="second value", default=2)
arg_parser.add_argument("--third", type=float, help="third value", default=3)
args = arg_parser.parse_args(args)
whatever = WhateverWhatever(args.first, args.second, args.third)
whatever.start()

class WhateverWhatever:
def __init__(self, first = 1, second = 2, third = 3):
self.first = first
self.second = second
self.third = third






python argparse






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 19:37







delphifissure

















asked Nov 19 '18 at 18:11









delphifissuredelphifissure

61




61








  • 3





    I don't understand. Can you give an example of what you want?

    – John Kugelman
    Nov 19 '18 at 18:16











  • You have a typo- args.three instead of args.third under whatever =. Beyond that, I agree with John Kugelman. You seem to already have what you want.

    – John Rouhana
    Nov 19 '18 at 18:20













  • How are you running this script? On what system, or with what shell? Normally we just use python myscript.py --first 3 --second 33 --third 43. Do you understnd what we mean by commandline arguments?

    – hpaulj
    Nov 19 '18 at 18:45











  • @JohnKugelman The above code defines the floats with default = x, I'd rather have a user prompt. Normally I'd just throw in something like first = input("first float") second = input("second float") ...but I get: TypeError("unsupported operand type(s) for *=: 'float' and 'NoneType'",)

    – delphifissure
    Nov 19 '18 at 19:31
















  • 3





    I don't understand. Can you give an example of what you want?

    – John Kugelman
    Nov 19 '18 at 18:16











  • You have a typo- args.three instead of args.third under whatever =. Beyond that, I agree with John Kugelman. You seem to already have what you want.

    – John Rouhana
    Nov 19 '18 at 18:20













  • How are you running this script? On what system, or with what shell? Normally we just use python myscript.py --first 3 --second 33 --third 43. Do you understnd what we mean by commandline arguments?

    – hpaulj
    Nov 19 '18 at 18:45











  • @JohnKugelman The above code defines the floats with default = x, I'd rather have a user prompt. Normally I'd just throw in something like first = input("first float") second = input("second float") ...but I get: TypeError("unsupported operand type(s) for *=: 'float' and 'NoneType'",)

    – delphifissure
    Nov 19 '18 at 19:31










3




3





I don't understand. Can you give an example of what you want?

– John Kugelman
Nov 19 '18 at 18:16





I don't understand. Can you give an example of what you want?

– John Kugelman
Nov 19 '18 at 18:16













You have a typo- args.three instead of args.third under whatever =. Beyond that, I agree with John Kugelman. You seem to already have what you want.

– John Rouhana
Nov 19 '18 at 18:20







You have a typo- args.three instead of args.third under whatever =. Beyond that, I agree with John Kugelman. You seem to already have what you want.

– John Rouhana
Nov 19 '18 at 18:20















How are you running this script? On what system, or with what shell? Normally we just use python myscript.py --first 3 --second 33 --third 43. Do you understnd what we mean by commandline arguments?

– hpaulj
Nov 19 '18 at 18:45





How are you running this script? On what system, or with what shell? Normally we just use python myscript.py --first 3 --second 33 --third 43. Do you understnd what we mean by commandline arguments?

– hpaulj
Nov 19 '18 at 18:45













@JohnKugelman The above code defines the floats with default = x, I'd rather have a user prompt. Normally I'd just throw in something like first = input("first float") second = input("second float") ...but I get: TypeError("unsupported operand type(s) for *=: 'float' and 'NoneType'",)

– delphifissure
Nov 19 '18 at 19:31







@JohnKugelman The above code defines the floats with default = x, I'd rather have a user prompt. Normally I'd just throw in something like first = input("first float") second = input("second float") ...but I get: TypeError("unsupported operand type(s) for *=: 'float' and 'NoneType'",)

– delphifissure
Nov 19 '18 at 19:31














3 Answers
3






active

oldest

votes


















0














The default parsing uses sys.argv[1:]



args = arg_parser.parse_args() 


You could also provide a similar list



args = arg_parser.parse_args('--first 1 --second 23 --third 42'.split()) 


It's a good idea when testing argparse to



print(args)


to see what the parser produced.



A matching Namespace object can be produced with:



 args = argparse.Namespace(first=1, second=43, third=23)


Or args can be any object with the relevant attributes, args.first, etc.






share|improve this answer































    0














    You can run your code in the console by writing



    python <PythonFileName.py> --first=<first input> --second=<second input> --third=<third input>


    you don't need to write an input method inside your code.






    share|improve this answer































      -1














      Well that turned out to be extremely obvious.



      import sys
      import argparse

      if __name__ == "__main__":
      args = sys.argv
      args.pop(0)
      arg_parser = argparse.ArgumentParser("Help")

      arg_parser.add_argument("--first", type=float, help="first value", default=1)
      arg_parser.add_argument("--second", type=float, help="second value", default=2)
      arg_parser.add_argument("--third", type=float, help="third value", default=3)
      args = arg_parser.parse_args(args)

      args.first = float(input("First value"))
      args.second = float(input("Second value"))
      args.third = float(input("Third value"))

      whatever = WhateverWhatever(args.first, args.second, args.third)
      whatever.start()

      class WhateverWhatever:
      def __init__(self, first = 1, second = 2, third = 3):
      self.first = first
      self.second = second
      self.third = third





      share|improve this answer



















      • 1





        If you're getting values from user input directly via input(), then all of the argument parsing is completely useless. Arg parse is for parsing command line inputs that are specified when the script is actually ran, not after it starts running.

        – Alexander Reynolds
        Nov 19 '18 at 20:05













      • I'm new to python but the above works for me within the context of my project. I'm jumping off from a pile of open source code that uses argparse from the get-go to set the variables when the script runs solo and just wanted a simple way to set the variables with a prompt vs. hardcoded defaults for testing purposes.

        – delphifissure
        Nov 19 '18 at 20:41











      • You should use an additional Python program in that case---the Python program can run, collect user input, and then call the function inside that main script. Otherwise if the program is run with variables, users will still be asked to overwrite them, which doesn't make much sense.

        – Alexander Reynolds
        Nov 19 '18 at 21:32











      • Very true. For my purposes it's not an issue (I'm the only user, this is a research project and I just need to validate some image capture algorithms IRL) but once it's ready for prime time I'll handle it as you suggest.

        – delphifissure
        Nov 19 '18 at 22:55











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


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53380412%2faccepting-user-input-for-argparse-arguments%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









      0














      The default parsing uses sys.argv[1:]



      args = arg_parser.parse_args() 


      You could also provide a similar list



      args = arg_parser.parse_args('--first 1 --second 23 --third 42'.split()) 


      It's a good idea when testing argparse to



      print(args)


      to see what the parser produced.



      A matching Namespace object can be produced with:



       args = argparse.Namespace(first=1, second=43, third=23)


      Or args can be any object with the relevant attributes, args.first, etc.






      share|improve this answer




























        0














        The default parsing uses sys.argv[1:]



        args = arg_parser.parse_args() 


        You could also provide a similar list



        args = arg_parser.parse_args('--first 1 --second 23 --third 42'.split()) 


        It's a good idea when testing argparse to



        print(args)


        to see what the parser produced.



        A matching Namespace object can be produced with:



         args = argparse.Namespace(first=1, second=43, third=23)


        Or args can be any object with the relevant attributes, args.first, etc.






        share|improve this answer


























          0












          0








          0







          The default parsing uses sys.argv[1:]



          args = arg_parser.parse_args() 


          You could also provide a similar list



          args = arg_parser.parse_args('--first 1 --second 23 --third 42'.split()) 


          It's a good idea when testing argparse to



          print(args)


          to see what the parser produced.



          A matching Namespace object can be produced with:



           args = argparse.Namespace(first=1, second=43, third=23)


          Or args can be any object with the relevant attributes, args.first, etc.






          share|improve this answer













          The default parsing uses sys.argv[1:]



          args = arg_parser.parse_args() 


          You could also provide a similar list



          args = arg_parser.parse_args('--first 1 --second 23 --third 42'.split()) 


          It's a good idea when testing argparse to



          print(args)


          to see what the parser produced.



          A matching Namespace object can be produced with:



           args = argparse.Namespace(first=1, second=43, third=23)


          Or args can be any object with the relevant attributes, args.first, etc.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 20 '18 at 20:14









          hpauljhpaulj

          112k782149




          112k782149

























              0














              You can run your code in the console by writing



              python <PythonFileName.py> --first=<first input> --second=<second input> --third=<third input>


              you don't need to write an input method inside your code.






              share|improve this answer




























                0














                You can run your code in the console by writing



                python <PythonFileName.py> --first=<first input> --second=<second input> --third=<third input>


                you don't need to write an input method inside your code.






                share|improve this answer


























                  0












                  0








                  0







                  You can run your code in the console by writing



                  python <PythonFileName.py> --first=<first input> --second=<second input> --third=<third input>


                  you don't need to write an input method inside your code.






                  share|improve this answer













                  You can run your code in the console by writing



                  python <PythonFileName.py> --first=<first input> --second=<second input> --third=<third input>


                  you don't need to write an input method inside your code.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 27 '18 at 7:40









                  Arjun BorkhatariyaArjun Borkhatariya

                  14




                  14























                      -1














                      Well that turned out to be extremely obvious.



                      import sys
                      import argparse

                      if __name__ == "__main__":
                      args = sys.argv
                      args.pop(0)
                      arg_parser = argparse.ArgumentParser("Help")

                      arg_parser.add_argument("--first", type=float, help="first value", default=1)
                      arg_parser.add_argument("--second", type=float, help="second value", default=2)
                      arg_parser.add_argument("--third", type=float, help="third value", default=3)
                      args = arg_parser.parse_args(args)

                      args.first = float(input("First value"))
                      args.second = float(input("Second value"))
                      args.third = float(input("Third value"))

                      whatever = WhateverWhatever(args.first, args.second, args.third)
                      whatever.start()

                      class WhateverWhatever:
                      def __init__(self, first = 1, second = 2, third = 3):
                      self.first = first
                      self.second = second
                      self.third = third





                      share|improve this answer



















                      • 1





                        If you're getting values from user input directly via input(), then all of the argument parsing is completely useless. Arg parse is for parsing command line inputs that are specified when the script is actually ran, not after it starts running.

                        – Alexander Reynolds
                        Nov 19 '18 at 20:05













                      • I'm new to python but the above works for me within the context of my project. I'm jumping off from a pile of open source code that uses argparse from the get-go to set the variables when the script runs solo and just wanted a simple way to set the variables with a prompt vs. hardcoded defaults for testing purposes.

                        – delphifissure
                        Nov 19 '18 at 20:41











                      • You should use an additional Python program in that case---the Python program can run, collect user input, and then call the function inside that main script. Otherwise if the program is run with variables, users will still be asked to overwrite them, which doesn't make much sense.

                        – Alexander Reynolds
                        Nov 19 '18 at 21:32











                      • Very true. For my purposes it's not an issue (I'm the only user, this is a research project and I just need to validate some image capture algorithms IRL) but once it's ready for prime time I'll handle it as you suggest.

                        – delphifissure
                        Nov 19 '18 at 22:55
















                      -1














                      Well that turned out to be extremely obvious.



                      import sys
                      import argparse

                      if __name__ == "__main__":
                      args = sys.argv
                      args.pop(0)
                      arg_parser = argparse.ArgumentParser("Help")

                      arg_parser.add_argument("--first", type=float, help="first value", default=1)
                      arg_parser.add_argument("--second", type=float, help="second value", default=2)
                      arg_parser.add_argument("--third", type=float, help="third value", default=3)
                      args = arg_parser.parse_args(args)

                      args.first = float(input("First value"))
                      args.second = float(input("Second value"))
                      args.third = float(input("Third value"))

                      whatever = WhateverWhatever(args.first, args.second, args.third)
                      whatever.start()

                      class WhateverWhatever:
                      def __init__(self, first = 1, second = 2, third = 3):
                      self.first = first
                      self.second = second
                      self.third = third





                      share|improve this answer



















                      • 1





                        If you're getting values from user input directly via input(), then all of the argument parsing is completely useless. Arg parse is for parsing command line inputs that are specified when the script is actually ran, not after it starts running.

                        – Alexander Reynolds
                        Nov 19 '18 at 20:05













                      • I'm new to python but the above works for me within the context of my project. I'm jumping off from a pile of open source code that uses argparse from the get-go to set the variables when the script runs solo and just wanted a simple way to set the variables with a prompt vs. hardcoded defaults for testing purposes.

                        – delphifissure
                        Nov 19 '18 at 20:41











                      • You should use an additional Python program in that case---the Python program can run, collect user input, and then call the function inside that main script. Otherwise if the program is run with variables, users will still be asked to overwrite them, which doesn't make much sense.

                        – Alexander Reynolds
                        Nov 19 '18 at 21:32











                      • Very true. For my purposes it's not an issue (I'm the only user, this is a research project and I just need to validate some image capture algorithms IRL) but once it's ready for prime time I'll handle it as you suggest.

                        – delphifissure
                        Nov 19 '18 at 22:55














                      -1












                      -1








                      -1







                      Well that turned out to be extremely obvious.



                      import sys
                      import argparse

                      if __name__ == "__main__":
                      args = sys.argv
                      args.pop(0)
                      arg_parser = argparse.ArgumentParser("Help")

                      arg_parser.add_argument("--first", type=float, help="first value", default=1)
                      arg_parser.add_argument("--second", type=float, help="second value", default=2)
                      arg_parser.add_argument("--third", type=float, help="third value", default=3)
                      args = arg_parser.parse_args(args)

                      args.first = float(input("First value"))
                      args.second = float(input("Second value"))
                      args.third = float(input("Third value"))

                      whatever = WhateverWhatever(args.first, args.second, args.third)
                      whatever.start()

                      class WhateverWhatever:
                      def __init__(self, first = 1, second = 2, third = 3):
                      self.first = first
                      self.second = second
                      self.third = third





                      share|improve this answer













                      Well that turned out to be extremely obvious.



                      import sys
                      import argparse

                      if __name__ == "__main__":
                      args = sys.argv
                      args.pop(0)
                      arg_parser = argparse.ArgumentParser("Help")

                      arg_parser.add_argument("--first", type=float, help="first value", default=1)
                      arg_parser.add_argument("--second", type=float, help="second value", default=2)
                      arg_parser.add_argument("--third", type=float, help="third value", default=3)
                      args = arg_parser.parse_args(args)

                      args.first = float(input("First value"))
                      args.second = float(input("Second value"))
                      args.third = float(input("Third value"))

                      whatever = WhateverWhatever(args.first, args.second, args.third)
                      whatever.start()

                      class WhateverWhatever:
                      def __init__(self, first = 1, second = 2, third = 3):
                      self.first = first
                      self.second = second
                      self.third = third






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Nov 19 '18 at 19:47









                      delphifissuredelphifissure

                      61




                      61








                      • 1





                        If you're getting values from user input directly via input(), then all of the argument parsing is completely useless. Arg parse is for parsing command line inputs that are specified when the script is actually ran, not after it starts running.

                        – Alexander Reynolds
                        Nov 19 '18 at 20:05













                      • I'm new to python but the above works for me within the context of my project. I'm jumping off from a pile of open source code that uses argparse from the get-go to set the variables when the script runs solo and just wanted a simple way to set the variables with a prompt vs. hardcoded defaults for testing purposes.

                        – delphifissure
                        Nov 19 '18 at 20:41











                      • You should use an additional Python program in that case---the Python program can run, collect user input, and then call the function inside that main script. Otherwise if the program is run with variables, users will still be asked to overwrite them, which doesn't make much sense.

                        – Alexander Reynolds
                        Nov 19 '18 at 21:32











                      • Very true. For my purposes it's not an issue (I'm the only user, this is a research project and I just need to validate some image capture algorithms IRL) but once it's ready for prime time I'll handle it as you suggest.

                        – delphifissure
                        Nov 19 '18 at 22:55














                      • 1





                        If you're getting values from user input directly via input(), then all of the argument parsing is completely useless. Arg parse is for parsing command line inputs that are specified when the script is actually ran, not after it starts running.

                        – Alexander Reynolds
                        Nov 19 '18 at 20:05













                      • I'm new to python but the above works for me within the context of my project. I'm jumping off from a pile of open source code that uses argparse from the get-go to set the variables when the script runs solo and just wanted a simple way to set the variables with a prompt vs. hardcoded defaults for testing purposes.

                        – delphifissure
                        Nov 19 '18 at 20:41











                      • You should use an additional Python program in that case---the Python program can run, collect user input, and then call the function inside that main script. Otherwise if the program is run with variables, users will still be asked to overwrite them, which doesn't make much sense.

                        – Alexander Reynolds
                        Nov 19 '18 at 21:32











                      • Very true. For my purposes it's not an issue (I'm the only user, this is a research project and I just need to validate some image capture algorithms IRL) but once it's ready for prime time I'll handle it as you suggest.

                        – delphifissure
                        Nov 19 '18 at 22:55








                      1




                      1





                      If you're getting values from user input directly via input(), then all of the argument parsing is completely useless. Arg parse is for parsing command line inputs that are specified when the script is actually ran, not after it starts running.

                      – Alexander Reynolds
                      Nov 19 '18 at 20:05







                      If you're getting values from user input directly via input(), then all of the argument parsing is completely useless. Arg parse is for parsing command line inputs that are specified when the script is actually ran, not after it starts running.

                      – Alexander Reynolds
                      Nov 19 '18 at 20:05















                      I'm new to python but the above works for me within the context of my project. I'm jumping off from a pile of open source code that uses argparse from the get-go to set the variables when the script runs solo and just wanted a simple way to set the variables with a prompt vs. hardcoded defaults for testing purposes.

                      – delphifissure
                      Nov 19 '18 at 20:41





                      I'm new to python but the above works for me within the context of my project. I'm jumping off from a pile of open source code that uses argparse from the get-go to set the variables when the script runs solo and just wanted a simple way to set the variables with a prompt vs. hardcoded defaults for testing purposes.

                      – delphifissure
                      Nov 19 '18 at 20:41













                      You should use an additional Python program in that case---the Python program can run, collect user input, and then call the function inside that main script. Otherwise if the program is run with variables, users will still be asked to overwrite them, which doesn't make much sense.

                      – Alexander Reynolds
                      Nov 19 '18 at 21:32





                      You should use an additional Python program in that case---the Python program can run, collect user input, and then call the function inside that main script. Otherwise if the program is run with variables, users will still be asked to overwrite them, which doesn't make much sense.

                      – Alexander Reynolds
                      Nov 19 '18 at 21:32













                      Very true. For my purposes it's not an issue (I'm the only user, this is a research project and I just need to validate some image capture algorithms IRL) but once it's ready for prime time I'll handle it as you suggest.

                      – delphifissure
                      Nov 19 '18 at 22:55





                      Very true. For my purposes it's not an issue (I'm the only user, this is a research project and I just need to validate some image capture algorithms IRL) but once it's ready for prime time I'll handle it as you suggest.

                      – delphifissure
                      Nov 19 '18 at 22:55


















                      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.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53380412%2faccepting-user-input-for-argparse-arguments%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

                      鏡平學校

                      ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

                      Why https connections are so slow when debugging (stepping over) in Java?