SyntaxError:keyword不能是表达式

时间:2016-10-28 14:52:49

标签: python-2.7

我有一个脚本来更改日期/时间,如下所示。
运行以下代码时,我一直收到以下错误:“date_from_now = datetime.now() + timedelta(kwargs['duration']=int(kwargs['offset']))

  File "/tmp/check.py", line 13
    date_from_now = datetime.now() + timedelta(kwargs['duration']=int(kwargs['offset']))
SyntaxError: keyword can't be an expression


import subprocess
import shlex
from datetime import datetime, timedelta
import time
import platform

def timecheck(**kwargs):
    OS = platform.uname()[0]
    print datetime.now()
    print kwargs['duration']
    print kwargs['offset']
    if OS == "SunOS":
        date_from_now = datetime.now() + timedelta(kwargs['duration']=int(kwargs['offset']))
        datelist = [str(date_from_now.hour), str(date_from_now.minute), str(date_from_now.day), str(date_from_now.month), str(date_from_now.year)[2:],str(date_from_now.second)]
        datelist = ["0" + elem for elem in datelist if len(elem) < 2]
        datestr = datelist[3] + datelist[2] +datelist[2] + datelist[0] + datelist[1] +  + datelist[4] +   datelist[5]
        print datestr
        subprocess.call(shlex.split("date '" + datestr + "'"))
    elif OS == "Linux":
        date_from_now = datetime.now() + timedelta(duration=int(offset))
        subprocess.call(shlex.split("date -s '" + date_from_now.strftime("%c") + "'"))

timecheck(offset="2",duration="hours")
timecheck(offset="2",duration="days")

不确定是由于上述错误。
请问有人可以提出建议吗?

提前致谢。

0 个答案:

没有答案