How to use argparse without using dest variable? [duplicate]
up vote
-1
down vote
favorite
This question already has an answer here:
Python argparse command line flags without arguments
3 answers
I want to use argparse
to get option to my program. Here is my sample program:
from argparse import ArgumentParser
parser = ArgumentParser()
print("enter the numbers:")
a=int(input("number 1:"))
b=int(input("number 2:"))
parser.add_argument('-a','--add')
parser.add_argument('-s','--sub')
options = parser.parse_args()
if options:
c=a+b
if options.d:
c=a-b
print(c)
it gives the output correctly if I use
python file.pu -a 1
But I don't want to give value like 1
in compilation. What I want is
python file.py -a
that performs addition.
python file.py -s
that performs subtraction.
How to change the code for it?
python python-3.x python-3.6
marked as duplicate by jonrsharpe
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 8:35
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
up vote
-1
down vote
favorite
This question already has an answer here:
Python argparse command line flags without arguments
3 answers
I want to use argparse
to get option to my program. Here is my sample program:
from argparse import ArgumentParser
parser = ArgumentParser()
print("enter the numbers:")
a=int(input("number 1:"))
b=int(input("number 2:"))
parser.add_argument('-a','--add')
parser.add_argument('-s','--sub')
options = parser.parse_args()
if options:
c=a+b
if options.d:
c=a-b
print(c)
it gives the output correctly if I use
python file.pu -a 1
But I don't want to give value like 1
in compilation. What I want is
python file.py -a
that performs addition.
python file.py -s
that performs subtraction.
How to change the code for it?
python python-3.x python-3.6
marked as duplicate by jonrsharpe
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 8:35
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
This question already has an answer here:
Python argparse command line flags without arguments
3 answers
I want to use argparse
to get option to my program. Here is my sample program:
from argparse import ArgumentParser
parser = ArgumentParser()
print("enter the numbers:")
a=int(input("number 1:"))
b=int(input("number 2:"))
parser.add_argument('-a','--add')
parser.add_argument('-s','--sub')
options = parser.parse_args()
if options:
c=a+b
if options.d:
c=a-b
print(c)
it gives the output correctly if I use
python file.pu -a 1
But I don't want to give value like 1
in compilation. What I want is
python file.py -a
that performs addition.
python file.py -s
that performs subtraction.
How to change the code for it?
python python-3.x python-3.6
This question already has an answer here:
Python argparse command line flags without arguments
3 answers
I want to use argparse
to get option to my program. Here is my sample program:
from argparse import ArgumentParser
parser = ArgumentParser()
print("enter the numbers:")
a=int(input("number 1:"))
b=int(input("number 2:"))
parser.add_argument('-a','--add')
parser.add_argument('-s','--sub')
options = parser.parse_args()
if options:
c=a+b
if options.d:
c=a-b
print(c)
it gives the output correctly if I use
python file.pu -a 1
But I don't want to give value like 1
in compilation. What I want is
python file.py -a
that performs addition.
python file.py -s
that performs subtraction.
How to change the code for it?
This question already has an answer here:
Python argparse command line flags without arguments
3 answers
python python-3.x python-3.6
python python-3.x python-3.6
edited Nov 20 at 8:34
jonrsharpe
76.4k10100206
76.4k10100206
asked Nov 20 at 8:33
joker
12
12
marked as duplicate by jonrsharpe
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 8:35
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by jonrsharpe
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 8:35
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
You can use:
action='store_true'
...in the following:
parser.add_argument('-a', '-add', action='store_true')
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You can use:
action='store_true'
...in the following:
parser.add_argument('-a', '-add', action='store_true')
add a comment |
up vote
0
down vote
You can use:
action='store_true'
...in the following:
parser.add_argument('-a', '-add', action='store_true')
add a comment |
up vote
0
down vote
up vote
0
down vote
You can use:
action='store_true'
...in the following:
parser.add_argument('-a', '-add', action='store_true')
You can use:
action='store_true'
...in the following:
parser.add_argument('-a', '-add', action='store_true')
answered Nov 20 at 8:39
Adam
1067
1067
add a comment |
add a comment |