Python Argparse: Issue with optional arguments which are negative numbers

后端 未结 7 1997
走了就别回头了
走了就别回头了 2020-12-08 13:59

I\'m having a small issue with argparse. I have an option xlim which is the xrange of a plot. I want to be able to pass numbers like <

相关标签:
7条回答
  • 2020-12-08 14:38

    Here is the code that I use. (It is similar to jeremiahbuddha's but it answers the question more directly since it deals with negative numbers.)

    Put this before calling argparse.ArgumentParser()

    for i, arg in enumerate(sys.argv):
      if (arg[0] == '-') and arg[1].isdigit(): sys.argv[i] = ' ' + arg
    
    0 讨论(0)
提交回复
热议问题