Created
November 3, 2016 14:57
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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