Search code examples
pythonargparseoptparse

String index out of range when converting to argparse


I changed from optparse to argparse but when I try to run it I get the following error:

    if not option_string[0] in self.prefix_chars:
IndexError: string index out of range

My code is:

usage = "%prog -f <fasta TFs> -a <database all> -s <database small> -d <pfam database> [options]"
version = "1.0.1"
description = " "
epilog = " "\
         " "
parser = argparse.ArgumentParser(usage=usage, description=description,
                      version="%prog "+version, epilog=epilog)

# options for running the program
# TF file
parser.add_argument("-f", "",  dest="TF", metavar="<file>",
                        help="input file with transcription factors")
parser.set_defaults(fasta=None)

I can't find where this error comes from, how can fix this?


Solution

  • The only way to get this error is by asking for an index that doesn't exist -- in this case, option_string must be empty.