我正在尝试使用logging.debug
打印变量并遇到以下错误,如何解决?
logging.debug('ATTEMPTS:{0}',attempts)
错误: -
Traceback (most recent call last):
File "C:\Python27\lib\logging\__init__.py", line 846, in emit
msg = self.format(record)
File "C:\Python27\lib\logging\__init__.py", line 723, in format
return fmt.format(record)
File "C:\Python27\lib\logging\__init__.py", line 464, in format
record.message = record.getMessage()
File "C:\Python27\lib\logging\__init__.py", line 328, in getMessage
msg = msg % self.args
TypeError: not all arguments converted during string formatting
答案 0 :(得分:1)
您可以使用
logging.debug('ATTEMPTS:%s', attempts)
或
logging.debug('ATTEMPTS:{0}'.format(attempts))
第一种方法将两个参数传递给logging.debug函数,该函数将自动格式化日志。第二种方法将一个预先格式化的字符串传递给logging.debug函数。
答案 1 :(得分:0)
您formatting the string错误,请尝试:
logging.debug('ATTEMPTS:{0}'.format(attempts))
答案 2 :(得分:-1)
你应该尝试
logging.debug('ATTEMPTS:{0}'.format(attempts))