Python:错误:“tuple”对象没有属性
调用函数时出现以下错误:logTestPython:错误:“tuple”对象没有属性,python,file-io,tuples,Python,File Io,Tuples,调用函数时出现以下错误:logTest # Log to File #This function logs line number, time, and message in log.txt def log(msg): global LOG_CNT LOG_CNT += 1 lineNumber = getframeinfo(currentframe()).lineno dts = time.strftime('%Y-%m-%d %H:%M:%S')
# Log to File
#This function logs line number, time, and message in log.txt
def log(msg):
global LOG_CNT
LOG_CNT += 1
lineNumber = getframeinfo(currentframe()).lineno
dts = time.strftime('%Y-%m-%d %H:%M:%S')
f = open('log.txt', 'a')
f.write('Log %d: Line %s: %s: %s\n' % (LOG_CNT, lineNumber, dts, msg))
f.close()
inspect.getframeinfo函数返回一个命名元组类型的回溯,lineno可能是返回的元组对象中成员的属性如果是inspect.getframeinfo,那么它应该返回一个inspect.Traceback实例。您是否重新定义了getframeinfo以使其返回元组?是否使用inspect.getframeinfo?
[error] script [ AutoSTO ] stopped with error in line 833
[error] AttributeError ( 'tuple' object has no attribute 'lineno' )
[error] --- Traceback --- error source first line: module ( function ) statement 72: main ( log ) lineNumber = getframeinfo(currentframe()).lineno
[error] --- Traceback --- end --------------