这是我的代码:
today = datetime.date.today()
if len(sys.argv) > 1:
arg_month = sys.argv[1]
arg_year = sys.argv[2]
print arg_month
print arg_year
lastMonth = datetime.date(day=1, month=arg_month, year=arg_year)
first = lastMonth + datetime.timedelta(month=1)
lastMonth = lastMonth.strftime("%Y%m")
curMonth = first.strftime("%Y%m")
else:
first = datetime.date(day=1, month=today.month, year=today.year)
lastMonth = first - datetime.timedelta(days=1)
lastMonth = lastMonth.strftime("%Y%m")
curMonth=(time.strftime("%Y%m"))
Run Code Online (Sandbox Code Playgroud)
这就是我运行代码的方式:python lelan.py 01 2015
输出是:
01
2015
Traceback (most recent call last):
File "lelan.py", line 22, in <module>
lastMonth = datetime.date(day=1, month=arg_month, year=arg_year)
TypeError: an integer is required
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题?谢谢.