I am trying to continue a dictionary value to the next line because it's too long but appears to still not be right. I have it broken up but apparently the indentation is now wrong too. Any ideas about how to best format this?
Asked
Active
Viewed 659 times
1

Heats
- 123
- 1
- 3
- 10
-
1Provide code that you have tried. – Rima Mar 12 '21 at 17:40
-
1What do you mean by "indentation is now wrong"? You are probably missing the space between `to` and `be`. But apart from that, that looks right. – Yevhen Kuzmovych Mar 12 '21 at 17:44
-
try replacing " with ''' and make it 1 line. – Kral Mar 12 '21 at 17:46
-
[Please don't post pictures of text](https://meta.stackoverflow.com/q/285551/4518341). Instead, copy the text, [edit] it into your post, and use the formatting tools like [code formatting](/editing-help#code). As well, please provide runnable code. What you've got pictured here is just a fragment. For reference see [mre]. – wjandrea Mar 12 '21 at 17:55
-
What's the problem with the indentation? That looks valid, so you shouldn't get an `IndentationError` or anything like that, but maybe you're getting a linter error/warning? For example, pycodestyle says `E128 continuation line under-indented for visual indent [pep8]`, though it goes away if you remove the parentheses. – wjandrea Mar 12 '21 at 18:00
-
1@Kral *"make it 1 line"* -- how does that help? OP wants to split a long line. – wjandrea Mar 12 '21 at 18:01
-
Does this answer your question? [How can I break up this long line in Python?](https://stackoverflow.com/questions/2058925/how-can-i-break-up-this-long-line-in-python) – Gino Mempin Mar 13 '21 at 00:34
2 Answers
0
String literal concatenation
d = {"question": ("this is "
"long data")}
print(d)
-
1You don't actually need a backslash here due to [string literal concatenation](https://docs.python.org/3/reference/lexical_analysis.html#string-literal-concatenation) – wjandrea Mar 12 '21 at 17:53
-
0
long_dict = {
"key": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, "
"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
}
EDIT:
Why this works: https://docs.python.org/3/reference/lexical_analysis.html#string-literal-concatenation (thanks @wjandrea )

konserw
- 494
- 2
- 10
-
1While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value. – Donald Duck Mar 13 '21 at 19:10