3

I am trying to print a variable using logging.debug and running into below error,how to fix it?

logging.debug('ATTEMPTS:{0}',attempts)

Error:-

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
1

3 Answers 3

3

You could either use

logging.debug('ATTEMPTS:%s', attempts)

or

logging.debug('ATTEMPTS:{0}'.format(attempts))

The first method passes two parameters into the logging.debug function which will automatically format the log. The second method passes in a single pre-formatted string into the logging.debug function.

Sign up to request clarification or add additional context in comments.

Comments

0

You're formatting the string incorrectly, try:

logging.debug('ATTEMPTS:{0}'.format(attempts))

Comments

-1

you should try as

logging.debug('ATTEMPTS:{0}'.format(attempts))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.