Accepting user input for Argparse arguments
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
add a comment |
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
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 usepython 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
add a comment |
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
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
python argparse
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 usepython 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
add a comment |
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 usepython 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
add a comment |
3 Answers
3
active
oldest
votes
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.
add a comment |
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.
add a comment |
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
1
If you're getting values from user input directly viainput()
, 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
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%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
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 20 '18 at 20:14
hpauljhpaulj
112k782149
112k782149
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Dec 27 '18 at 7:40
Arjun BorkhatariyaArjun Borkhatariya
14
14
add a comment |
add a comment |
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
1
If you're getting values from user input directly viainput()
, 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
add a comment |
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
1
If you're getting values from user input directly viainput()
, 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
add a comment |
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
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
answered Nov 19 '18 at 19:47
delphifissuredelphifissure
61
61
1
If you're getting values from user input directly viainput()
, 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
add a comment |
1
If you're getting values from user input directly viainput()
, 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
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%2f53380412%2faccepting-user-input-for-argparse-arguments%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
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