2016-07-01 12 views
0

Ich versuche, eine Variable mit logging.debug zu drucken und in unten Fehler zu laufen, wie es zu beheben?logging.debug Fehler während der Formatierung der Zeichenfolge

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

Fehler: -

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 
+2

Mögliches Duplikat von [TypeError: nicht alle Argumente wurden während der Formatierung von Python konvertiert] (http://stackoverflow.com/questions/18053500/typeerror-not-all-arguments-converted-during-string-formatting-python) – antiguru

Antwort

-1

Sie sollten versuchen

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

Sie cou ld entweder Verwendung

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

oder

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

Die erste Methode übergibt zwei Parameter in die logging.debug Funktion, die automatisch das Protokoll formatiert wird. Die zweite Methode übergibt eine einzelne vorformatierte Zeichenfolge an die Funktion logging.debug.

Verwandte Themen