使用Python解析crontab表达式的时候,split
不用传递参数,使用默认行为,可以正确拆分出5个值,而使用了单空格拆分,由于用户可能会输入多个空格分隔,从而解析错误
示例
cron_exp = ' * * * * * '
# 正确✅
print(cron_exp.split())
# ['*', '*', '*', '*', '*']
# 错误❌
print(cron_exp.split(' '))
# ['', '*', '', '*', '', '*', '', '', '*', '', '*', '']