This is my script mytest.py.
import argparse
parser = argparse.ArgumentParser(description="Params")
parser.add_argument(
"--value")
def test(args):
print(args.value)
args = parser.parse_args()
test(args)
I want to pass argument store in variable val
val =1
!python mytest.py --value val
instead of printing 1 it print val
. How to send 1 stored in variable val.
argparse
always get argument as string, or list of strings on default, and what you do on your shell is irrelevant with python program. It is no wonder val
is printed.
Use file that contains "1" and read that file to do what you intended to.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.