Python 我如何修复';局部变量';上一次';在转让前参考的第6行的封闭范围中定义;错误
我正在使用python的“时间”库,现在我正在获取一个要更新的日期变量。现在我的代码是这样的Python 我如何修复';局部变量';上一次';在转让前参考的第6行的封闭范围中定义;错误,python,datetime,error-handling,shared-libraries,Python,Datetime,Error Handling,Shared Libraries,我正在使用python的“时间”库,现在我正在获取一个要更新的日期变量。现在我的代码是这样的 def getTime(): named_tuple = time.localtime() time_string = time.strftime("%m/%d/%Y", named_tuple) prev_time = time_string getTime() if prev_time != time_string: getTime() 在“prev_tim
def getTime():
named_tuple = time.localtime()
time_string = time.strftime("%m/%d/%Y", named_tuple)
prev_time = time_string
getTime()
if prev_time != time_string:
getTime()
在“prev_time!=time string”中:“我不断得到错误”'local variable'prev_time'在赋值前引用的第6行的封闭范围中定义“我对python相对较新,因此非常感谢您的帮助!提前谢谢 尝试使用全局作用域
def getTime():
全局上一次时间,时间字符串
named_tuple=time.localtime()
time\u string=time.strftime(“%m/%d/%Y”,命名为\u tuple)
上一个时间=时间字符串
getTime()
如果上一次时间字符串:
getTime()