Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23305

Python argparser ignoring options present

$
0
0

I have a python project with several command line (argparser) options which have been working. I went to modify the --scan arg to accept a integer and now several of the options are not being accepted with the error:

error: unrecognized arguments: --radio airspy --scan

They are also not shown when I run myproject -h - despite being present in the code as arg options.

This started when I created a issue on GitHub for myproject and then a new branch based on the issue. I checked this branch out on VSCode to add a integer option to the argparser for --scan.

In a further effort to isolate the cause I then tried to check out the previously working branch and it too now gets unrecognised arguments error.

I am trying the command myproject --radio airspy --center-freq 160500000 --carrier 160380123 --scan

My full arg parser code is here:

    p = argparse.ArgumentParser()p.add_argument("-f","--from-file",    dest="infile",    help="Read samples from the given filename and process them",)p.add_argument("-db","--database",    dest="db",    default=None,    help="SQLite database where to store processed results. Defaults to `main.db`. Environment variable KIWITRACKER_DB has priority.",)p.add_argument("-d","--delete-database",    dest="deletedb",    action="store_true",    help="If SQLite database file exists upon start, it is deleted.",)p.add_argument("-o","--outfile",    dest="outfile",    help="Read samples from the device and save to the given filename",)p.add_argument("-m","--max-samples",    dest="max_samples",    type=int,    help='Number of samples to read when "-o/--outfile" is specified',)p.add_argument("--scan",    dest="scan",    action="store_true",    help="Scan for frequencies in first 3sec",)p.add_argument("--no-use-gps",    dest="no_use_gps",    action="store_true",    help="Set this flag to not use GPS module",)p.add_argument("--radio",    default="rtl",    const="rtl",    nargs="?",    choices=["rtl", "airspy", "dummy"],    help="type of radio to be used (default: %(default)s), ignored if reading samples from disk.",)s_group = p.add_argument_group("Sampling")s_group.add_argument("-c","--chunk-size",    dest="chunk_size",    type=int,    default=SampleConfig.read_size,    help="Chunk size for sdr.read_samples (default: %(default)s)",)s_group.add_argument("-s","--sample-rate",    dest="sample_rate",    type=float,    default=SampleConfig.sample_rate,    help="SDR sample rate (default: %(default)s)",)s_group.add_argument("--center-freq",    dest="center_freq",    type=float,    default=SampleConfig.center_freq,    help="SDR center frequency (default: %(default)s)",)s_group.add_argument("-g","--gain",    dest="gain",    type=float,    default=SampleConfig.gain,    help="SDR gain (default: %(default)s)",)s_group.add_argument("--bias-tee",    dest="bias_tee",    action="store_true",    help="Enable bias tee",)s_group.add_argument("-log", "--loglevel", default="warning", help="Provide logging level. Example --loglevel debug, default=warning")p_group = p.add_argument_group("Processing")p_group.add_argument("--carrier",    dest="carrier",    type=float,    nargs="?",    const=ProcessConfig.carrier_freq,    # default=ProcessConfig.carrier_freq,    help="Carrier frequency to process (default: %(default)s)",)args = p.parse_args()

And if I try myproject -h the output is missing several options:

$ myproject -husage: myproject [-h] [-f INFILE] [-o OUTFILE] [-m MAX_SAMPLES] [-c CHUNK_SIZE] [-s SAMPLE_RATE] [--center-freq CENTER_FREQ] [-g GAIN] [--bias-tee] [--carrier CARRIER]options:  -h, --help            show this help message and exit  -f INFILE, --from-file INFILE                    Read samples from the given filename and process them  -o OUTFILE, --outfile OUTFILE                    Read samples from the device and save to the given filename  -m MAX_SAMPLES, --max-samples MAX_SAMPLES                    Number of samples to read when "-o/--outfile" is specifiedSampling:  -c CHUNK_SIZE, --chunk-size CHUNK_SIZE                    Chunk size for sdr.read_samples (default: 65536)  -s SAMPLE_RATE, --sample-rate SAMPLE_RATE                    SDR sample rate (default: 1024000.0)  --center-freq CENTER_FREQ                    SDR center frequency (default: 160270968)  -g GAIN, --gain GAIN  SDR gain (default: 7.7)  --bias-tee            Enable bias teeProcessing:  --carrier CARRIER     Carrier frequency to process (default: 160270968)

It feels like a configuration option. The setup is VSCode 1.89 and I am running on Windows 10 but editing the code on a remote RaspPi over ssh shell from VS Code.

I have saved the project several times.


Viewing all articles
Browse latest Browse all 23305

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>