Skip to content

Instantly share code, notes, and snippets.

@ischurov
Created November 3, 2016 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ischurov/8e2cb3be3ec0a668a0d39a33471c3ad3 to your computer and use it in GitHub Desktop.
Save ischurov/8e2cb3be3ec0a668a0d39a33471c3ad3 to your computer and use it in GitHub Desktop.
This gist provides a function that makes pep-8-friendly multiline representation of long string.
def repr_long_str(s, maxlen=70, correction=-1, doprint=False):
assert maxlen > 3
cur = 0
out = []
while cur < len(s):
end = cur + maxlen - 2 + correction
while len(repr(s[cur:end])) > maxlen + correction:
end -= 1
out.append(repr(s[cur:end]))
correction = 0
cur = end
ret = "(" + "\n".join(out) + ")"
if doprint:
print(ret)
return
return ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment