How to avoid extra spaces in the logger file caused by indexes

today i have applied the coding convention PEP 8

in my project. So I smashed mine 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 what I get in my logger file:

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 spaces after the word descriptor. I know if I do something like this:

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

      

It will work, but it looks silly and even more if you have more padding. How do I avoid extra spaces in my log file?

+3


source to share


2 answers


logger.debug((
              "Returning a list of Window handles"
              "with specified Windowtitle: {}"
             ).format(title))

      



+3


source


This could be an alternative way



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

      

+1


source







All Articles