How to avoid additional whitespaces in loggerfile, caused by indentions

47 views Asked by At

today i applied the PEP 8 coding convention on my project. Therefore i splitted my logger.debug to avoid E501 line to long. This is what i have now:

def find_window():
    ...
    logger.debug("Returning a List of Window handles\
                with specified Windowtitle: {}".format(title))

So far, so good, but the bad news is, this is what i get in my loggerfile:

06/25/2015 02:07:20 PM - DEBUG - libs.Window on 104 : Returning a List of Window handles with specified Windowtitle: desktop: notepad

There are additional whitespaces after the word handles. I know if i do something like this:

def find_window():
    ...
    logger.debug("Returning a List of Window handles \
with specified Windowtitle: {}".format(title))

This would work, but it looks stupid and even more if u have more indentions. How do i avoid this extra whitespaces in my loggerfile?

2

There are 2 answers

0
FunkySayu On BEST ANSWER
logger.debug((
              "Returning a list of Window handles"
              "with specified Windowtitle: {}"
             ).format(title))
0
Naman Sogani On

This can be an alternative way

import re
logger.debug(re.sub('\s+', ' ', "Returning a List of Window handles\
                                 with specified Windowtitle: {}".format(title)))