Python: correctly parse crontab expressions

When using Python to parse crontab expressions, splitthere is no need to pass parameters, and the default behavior can be used to correctly split 5 values. However, if single-space split is used, the user may enter multiple spaces to separate, resulting in parsing errors.

example

cron_exp = ' *  *  *   *  * '

# 正确✅
print(cron_exp.split())
# ['*', '*', '*', '*', '*']

# 错误❌
print(cron_exp.split(' '))
# ['', '*', '', '*', '', '*', '', '', '*', '', '*', '']

Guess you like

Origin blog.csdn.net/mouday/article/details/131906308