Changes

→‎Miscellaneous: add guidelines on strings, highlight code, add hint on string logging
Line 48: Line 48:     
== Miscellaneous ==
 
== Miscellaneous ==
* Use logging.debug('foo %r bar', x) instead of logging.debug('foo %r bar' % x). This is more robust and formatting only happens if we actually log something.
+
* Use <code>logging.debug('foo %r bar', x)</code> instead of <code>logging.debug('foo %r bar' % x)</code>. This is more robust and formatting only happens if we actually log something.
 +
* When logging strings, consider using <code>%r</code> instead of <code>%s</code> because <code>%r</code> will take care of quoting and escaping the string as needed
 
* When you catch an exception and want to log it, use logging.exception(), this will print the whole backtrace and exception information, which is very useful when debugging.
 
* When you catch an exception and want to log it, use logging.exception(), this will print the whole backtrace and exception information, which is very useful when debugging.
 +
* "Short" string literals should use single quotes (<code>'</code>) unless the string contains a single quote (that would need to be escaped)
 +
* "Long" string literals should use three double quotes (<code>"""</code>)
    
== Tools ==
 
== Tools ==
344

edits