我有 4 個類和 1 個介面,當我執行我的類 Fingerprinter 時出現此錯誤:
TypeError: unsupported operand type(s) for : 'DatetimeArray' and 'str'.
問題是我def __str__(self)在課堂上的功能Fingerprinter:
def __str__(self):
return self._data_h_df ', ' str(self._modeCB) ', ' str(self._outputMode)
這是我的代碼:
class OutputMode(object):
def __init__(self,name,startTime,intervalSeconds,timezone):
self.__name = name
self.__startTime = startTime
self.__intervalSeconds = intervalSeconds
self.__timezone = timezone
class Fingerprinter(object):
def __init__(self,data_h_df,outputMode,modeCB=CONST_MODE_CONT):
self._data_h_df = data_h_df
self._modeCB = modeCB
self._outputMode = outputMode
def _generateID(data_h_df):
pass
def run(self):
return self._generateID(data_h_df)
def __str__(self):
return self._data_h_df ', ' str(self._modeCB) ', ' str(self._outputMode)
outputMode = OutputMode('EEA','06:00',8*3600,pytz.timezone('Europe/Paris'))
test = Fingerprinter(data_h_df, outputMode, CONST_MODE_CONT)
print(outputMode)
print(test)
uj5u.com熱心網友回復:
您的問題self._data_h_df可能是日期陣列(或至少不是 str),因此無法添加到 str 中。嘗試:
def __str__(self):
return str(self._data_h_df) ', ' str(self._modeCB) ', ' str(self._outputMode)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/380218.html
下一篇:無論如何要洗掉C#類屬性的重復?
