Python Forum
argparser not showing all options
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
argparser not showing all options
#1
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 several options are missing:

Output:
$ myproject -h usage: 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 specified Sampling: -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 tee Processing: --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.

What is causing these options not to be picked up?
deanhystad write May-22-2024, 02:40 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
Please post the code that generates your error, not the code that works.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  covertion of argparser to cliff suraj522 0 1,319 Sep-11-2019, 07:36 AM
Last Post: suraj522
  covertion of argparser to cliff suraj522 0 2,133 Sep-10-2019, 07:48 AM
Last Post: suraj522
  Help with options raiden 1 2,017 Aug-30-2019, 12:57 AM
Last Post: scidam
  Display options - screen tcpip 2 2,934 Feb-06-2018, 02:41 PM
Last Post: tcpip
  Return options Kongurinn 1 3,384 Sep-28-2017, 03:02 PM
Last Post: ichabod801
  Python Launch Options Flexico 6 7,271 Dec-07-2016, 06:58 AM
Last Post: Flexico

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020