我升級我的Mac OS 10.9環境到Python 3.3,現在當我運行一個Python腳本的lib我得到以下錯誤:的Python 3加薪類型錯誤,「Time.milliseconds預計DateTime對象
加薪類型錯誤」 Time.milliseconds預計日期時間對象
這裏的分離的代碼,顯然會導致錯誤:
@classmethod
def to_unix(cls, timestamp):
""" Wrapper over time module to produce Unix epoch time as a float """
if not isinstance(timestamp, datetime.datetime):
raise TypeError, 'Time.milliseconds expects a datetime object'
base = time.mktime(timestamp.timetuple())
return base
,這裏是在整個部分,其中上述代碼駐留的代碼:
@classmethod
def from_unix(cls, seconds, milliseconds = 0):
""" Produce a full |datetime.datetime| object from a Unix timestamp """
base = list(time.gmtime(seconds))[0:6]
base.append(milliseconds * 1000) # microseconds
return datetime.datetime(* base)
@classmethod
def to_unix(cls, timestamp):
""" Wrapper over time module to produce Unix epoch time as a float """
if not isinstance(timestamp, datetime.datetime):
raise TypeError, 'Time.milliseconds expects a datetime object'
base = time.mktime(timestamp.timetuple())
return base
@classmethod
def milliseconds_offset(cls, timestamp, now = None):
""" Offset time (in milliseconds) from a |datetime.datetime| object to now """
if isinstance(timestamp, (int, float)):
base = timestamp
else:
base = cls.to_unix(timestamp)
base = base + (timestamp.microsecond/1000000)
if now is None:
now = time.time()
return (now - base) * 1000
這可能是引用這些庫之一:
import date time
import time
任何想法?升級前我沒有這個錯誤,所以可能是重新定義了時間戳或日期時間?
謝謝
您沒有顯示調用代碼。追溯會很好。 –