Argparse参数数量限制
创始人
2024-09-13 06:00:33
0

当使用argparse模块解析命令行参数时,有时候需要处理大量的参数数量。默认情况下,argparse的参数数量限制为100个,为了避免出现参数数量限制的问题,可以通过添加一些参数来解决这个问题。

一种解决方法是使用argparse.ArgumentParser()类中的max_ argument_ number参数。这个参数设置了命令行参数的最大数量限制。例如,将其设置为1000:

parser = argparse.ArgumentParser(description='Add some integers.')
parser.add_argument('integers', metavar='N', type=int, nargs='+',
                   help='an integer for the accumulator')
parser.add_argument('--sum', dest='accumulate', action='store_const',
                   const=sum, default=max,
                   help='sum the integers (default: find the max)')
parser.add_argument('--max-args', dest='maxargs', type=int, default=1000,
                   help='maximum number of arguments to parse')
args = parser.parse_args()

注意:这种方法在argparse模块版本3.6之前不可用。

另一种解决方法是使用sys模块的setrecursionlimit()函数,该函数允许程序设置最大递归限制数量。在解析命令行参数时,argparse使用递归函数,因此可以增加递归限制数量以避免参数数量限制问题。例如,将递归限制数量设置为10000:

import sys
sys.setrecursionlimit(10000)

parser = argparse.ArgumentParser(description='Add some integers.')
parser.add_argument('integers', metavar='N', type=int, nargs='+',
                   help='an integer for the accumulator')
parser.add_argument('--sum', dest='accumulate', action='store_const',
                   const=sum, default=max,
                   help='sum the integers (default: find the max)')
args = parser.parse_args()

相关内容

热门资讯

wepoke辅助插件!wepo... wepoke辅助插件!wepoke存在外挂(辅助挂)原来是真的有挂(详细辅助软件教程);大神普及一款...
德州ai人工智能!微扑克系统发... 德州ai人工智能!微扑克系统发牌(透视辅助)确实是真的有挂(详细辅助黑科技教程);原来确实真的有挂(...
智星德州菠萝外挂!微扑克wpk... 智星德州菠萝外挂!微扑克wpk辅助软件(透视辅助)的确真的有挂(详细辅助透视脚本教程);大神普及一款...
aapoker猫腻!aapok... aapoker猫腻!aapoker俱乐部后天可以操作(黑科技)竟然真的有挂(详细辅助软件教程);《W...
微扑克辅助软件!wpk数据抓包... 微扑克辅助软件!wpk数据抓包(黑科技辅助挂)的确是真的有挂(详细辅助脚本教程);亲,其实确实真的有...
wpk有辅助挂!wepoke是... wpk有辅助挂!wepoke是有软件(黑科技)原来真的有挂(详细透视脚本教程);1.wepoke a...
wpk ai辅助!德扑之星有规... wpk ai辅助!德扑之星有规律(透视辅助)竟然真的有挂(详细辅助透视脚本教程)准备好在 ia的高塔...
wpk提高胜率!众合推扑克辅助... wpk提高胜率!众合推扑克辅助工具(透视)的确真的有挂(详细辅助挂教程);最新版本免费下载安装哦,具...
微扑克ai辅助!wepoke软... 相信很多朋友都在电脑上玩过wepoke吧,但是很多朋友都在抱怨用电脑玩起来不方便。为此小编给大家带来...
德州免费辅助神器app!pok... 1、德州免费辅助神器app!pokerx机器人(软件透明该)竟然真的有挂(详细代打辅助教程);详细教...