pythonindentationpep8long-lines

How to deal with long lines in Python?


I have this really long line in Python, due to several reasons, that I'm trying to break up.

long_variable_name = somelongmodule.SomeLongClassName.VeryLongFunctionName(...

I know the recommended way to break up a line is at the parentheses, but I haven't even gotten there yet. What might be some solution to this problem?


Solution

  • A very long function name is probably unproblematic to import directly:

    from somelongmodule.SomeLongClassName import VeryLongFunctionName
    
    long_variable_name = VeryLongFunctionName(...
    

    And/or break the line after the variable name:

    long_variable_name = \
        somelongmodule.SomeLongClassName.VeryLongFunctionName(...
    

    Also, you might want to try not having very long names in the first place.