argparse

Argparse error with TensorFlow's cifar10.py

回眸只為那壹抹淺笑 提交于 2019-12-02 17:43:27
问题 I get the following error when I run python cifar10.py : argparse.ArgumentError: argument --batch_size: conflicting option string(s): --batch_size Here's the full output of the run including a complete trace: I tensorflow/stream_executor/dso_loader.cc:101] successfully opened CUDA library libcublas.so.7.0 locally I tensorflow/stream_executor/dso_loader.cc:101] successfully opened CUDA library libcudnn.so.6.5 locally I tensorflow/stream_executor/dso_loader.cc:101] successfully opened CUDA

Getting the remaining arguments in argparse

坚强是说给别人听的谎言 提交于 2019-12-02 17:25:28
I want to get all the remaining unused arguments at once. How do I do it? parser.add_argument('-i', action='store', dest='i', default='i.log') parser.add_argument('-o', action='store', dest='o', default='o.log') Another option is to add a positional argument to your parser. Specify the option without leading dashes, and argparse will look for them when no other option is recognized. This has the added benefit of improving the help text for the command: >>> parser.add_argument('otherthings', nargs='*') >>> parser.parse_args(['foo', 'bar', 'baz']) Namespace(i='i.log', o='o.log', otherthings=[

Can I convert a namespace object from mutable to immutable?

自古美人都是妖i 提交于 2019-12-02 17:04:01
问题 I receive a namespace object from command line arguments. And I don't want to modify it. Can I do that or do you have some ideas? # -*- coding: utf-8 -*- import argparse def parse_args(): parser = argparse.ArgumentParser(description='This script is ...') parser.add_argument('--confdir', type=str, required=True) parser.add_argument('--outdir', type=str, required=True) return parser.parse_args() if __name__ == '__main__': mutable_namespace = parse_args() # I want to prevent overwrite like that.

Python does not state the line of code that an error refers to

痴心易碎 提交于 2019-12-02 12:21:17
I have tried to correct the following error which basically is about the arguments for 'username' and 'directory'. I have tried all possible ways but no luck. Python does not state the line of code that the following error refers to: usage: Google_Map.py [-h] [-n NUM_TO_DOWNLOAD] [-l LOG_LEVEL] username directory Google_Map.py: error: the following arguments are required: username, directory Please see the code here: def __init__(self, username, directory, num_to_download = 10, log_level='info'): self.username = username self.profile_url = self.get_url(username) self.directory = directory self

Can I convert a namespace object from mutable to immutable?

﹥>﹥吖頭↗ 提交于 2019-12-02 12:06:57
I receive a namespace object from command line arguments. And I don't want to modify it. Can I do that or do you have some ideas? # -*- coding: utf-8 -*- import argparse def parse_args(): parser = argparse.ArgumentParser(description='This script is ...') parser.add_argument('--confdir', type=str, required=True) parser.add_argument('--outdir', type=str, required=True) return parser.parse_args() if __name__ == '__main__': mutable_namespace = parse_args() # I want to prevent overwrite like that. mutable_namespace.confdir = "xxx" I initially proposed the custom Namespace class, but I like this

Chaining in a command line several tranformations with options

喜欢而已 提交于 2019-12-02 10:19:59
My command line utility should accept several filters attached to each other (similar to Unix pipeline). Each filter has a number of options. For example chain filter currently has the following options: -t NAMESPACE, --target NAMESPACE target namespace(s) -s {precedence,doc}, --next-script {precedence,doc} "next script" algorithm ("precedence" is not supported) -n {ignore,remove,error}, --not-in-target {ignore,remove,error} what if a result is not in target NS -u URL, --universal-precedence URL universal precedence -W {inverseofsum,sumofinverses}, --weight-formula {inverseofsum,sumofinverses}

Argparse error with TensorFlow's cifar10.py

人盡茶涼 提交于 2019-12-02 10:03:00
I get the following error when I run python cifar10.py : argparse.ArgumentError: argument --batch_size: conflicting option string(s): --batch_size Here's the full output of the run including a complete trace: I tensorflow/stream_executor/dso_loader.cc:101] successfully opened CUDA library libcublas.so.7.0 locally I tensorflow/stream_executor/dso_loader.cc:101] successfully opened CUDA library libcudnn.so.6.5 locally I tensorflow/stream_executor/dso_loader.cc:101] successfully opened CUDA library libcufft.so.7.0 locally I tensorflow/stream_executor/dso_loader.cc:101] successfully opened CUDA

Importing variables from a namespace object in Python

安稳与你 提交于 2019-12-02 07:09:41
问题 Say I have a namespace args that I obtain from calling parser.parse_args() , which parses the command line arguments. How can I import all variables from this namespace to my current namespace? e.g. parser.add_argument('-p', '--some_parameter', default=1) args = parser.parse_args() # ... code to load all variables defined in the namespace args ... print some_parameter I could certainly do: some_parameter = args.some_parameter but if I have a large number of parameters I would need one such

Can argparse accept argument value as key=val pairs

孤者浪人 提交于 2019-12-02 06:54:43
I am trying to implement below option by using argparse(can't use any other tool like docopt because of project requirement):- cli.py --conf key1=value1, key2=value2, kay3=value3 or cli.py --conf key1=value1 key2=value2 key3=value3 So far I have tried type=json.loads or dict but not helping. One possible solution is to use type=str and then later parse it to dict . Do you guys know any other better solution which I am missing.. Thanks in advance. Note- Can't use --key1=value1 --key2=value2 --key3=value3 because I don't want to restrict count and name of key/value. It will help in supporting

python argparse, how to refer args by their name

纵饮孤独 提交于 2019-12-02 06:50:35
问题 this is a question about argparse in python, it is probably very easy import argparse parser=argparse.ArgumentParser() parser.add_argument('--lib') args = parser.parse_known_args() if args.lib == 'lib': print 'aa' this would work, but instead of calling args.lib, i only want to say 'lib' (i dont want to type more), is there a way to export all the args variable out of the module (ie changing scope). so that i can directly check the value of lib not by specifying name of the module at the