0

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?

user3757652
  • 35
  • 1
  • 2
  • 6
  • You could save it to a variable: `shorter_name = somelongmodule.SomeLongClassName.VeryLongFunctionName` then `shorter_name( ... )`. – agconti May 17 '15 at 01:42
  • Make a temporary variable: `descriptive_name = somelongmodule.SomeLongClassName.very_long_function_name` / `actual_variable = descriptive_name(...)` – Navith May 17 '15 at 01:42
  • See https://stackoverflow.com/questions/53162/how-can-i-do-a-line-break-line-continuation-in-python or https://stackoverflow.com/questions/4172448/is-it-possible-to-break-a-long-line-to-multiple-lines-in-python. While parentheses are preferred (and you can add an extra pair), you can also use "\" to break up a line. – ViennaMike May 17 '15 at 01:49
  • Hmm, I mostly wanted to know a 'best way' of doing things in Python. I could have monkeyed around with temp vars but I wasn't sure if that was the best way about it. The original names are from a library. – user3757652 May 17 '15 at 02:29

1 Answers1

1

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.

Stefan Pochmann
  • 27,593
  • 8
  • 44
  • 107