Reputation: 19395
I am trying to run (from Spyder) a python script that contains the following code:
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Project description')
parser.add_argument(
'nbr_workers', type=int, help='Number of workers e.g. 1, 2, 4, 8')
parser.add_argument(
'--nbr_samples_in_total',
type=int,
default=1e4,
help='Number of samples in total e.g. 100000000')
parser.add_argument(
'--processes',
action="store_true",
default=True,
help='True if using Processes, absent (False) for Threads')
I know that I can use control + F6 in Spyder to submit command line options. However, I am not able to make it work.
Entering
generate the error
runfile('C:/Users/john/.spyder/temp.py', args='3 1000 1', wdir='C:/Users/john/.spyder')
usage: temp.py [-h] [--nbr_samples_in_total NBR_SAMPLES_IN_TOTAL]
[--processes]
nbr_workers
temp.py: error: unrecognized arguments: 1000 1
An exception has occurred, use %tb to see the full traceback.
SystemExit: 2
What am I doing wrong here? Thanks!
Upvotes: 1
Views: 841
Reputation: 1431
Ok i think i found the solution.
runfile('//***/.spyder/temp.py', args='3 --nbr_samples_in_total 100 --processes', wdir='//***/.spyder')
OUT: Namespace(nbr_samples_in_total=100, nbr_workers=3, processes=True)
runfile('//***/.spyder/temp.py', args='3 --nbr_samples_in_total 100', wdir='//***/.spyder')
OUT: Namespace(nbr_samples_in_total=100, nbr_workers=3, processes=False)
You have to ammend the process flag to default=False
as you mentioned in your comment absent(false), that way if you do add the flag it'll be set to True
Upvotes: 2