Search code examples
pythonpep8

E501 line too long (Break up a Directory)


I have a function which effectively converts a file's contents to a UTF-8 format and writes it to a new file using os.system. It all works, no problems there. My issue is just when running pylama, I get the E501 error and want to fix it. I have already split the line after the iconv flags, but what is the syntax to split a directory? I tried something like /usr/local/bin/\ and that didn't work out so well.

def test():
    os.system('iconv -f utf-8 -t utf-8 -c \
              /usr/local/bin/program/files/file.txt > /usr/local/bin/program/files/file2.txt')

Solution

  • You can combine strings from multiple lines in Python using the backslash character (\) outside of the string itself, e.g.:

        os.system('iconv -f utf-8 -t utf-8 -c ' \
                  '/usr/local/bin/program/files/file.txt > ' \
                 '/usr/local/bin/program/files/file2.txt')