-1

I had a look at using escape \ to fix it but it's not really making sense. The top line gives string literal is undetermined, and the last square bracket before the closing " gives Statements must be separated by newlines or semicolons error.

    line = "48,[['c0', 700, 2401], ['c1', 300, 2002], ['c2', 100, 1803], ['c3', 900, 
2604], ['c4', 200, 1905], ['c5', 700, 2406], ['c8', 1200, 2909], ['c11', 
600, 2312], ['c14', 400, 2115], ['c28', 500, 2229], ['c29', 300, 2030], 
['c31', 1200, 2932], ['c35', 1600, 3336], ['c36', 1700, 3437], ['c39', 
300, 2040], ['c13', 800, 3215], ['c17', 1600, 5230], ['c15', 1600, 5229], 
['c19', 1100, 4335], ['c10', 1500, 3513], ['c22', 900, 4535], ['c9', 1800, 
3715], ['c18', 900, 4532], ['c7', 1000, 3612], ['c12', 500, 3117], ['c16', 
700, 4329], ['c6', 500, 2913], ['c20', 1400, 4334], ['c30', 1200, 5763], 
['c25', 1500, 5860], ['c27', 700, 5958], ['c26', 900, 6157], ['c24', 1800, 
7054], ['c23', 500, 5753], ['c21', 1200, 3534], ['c37', 300, 7392], 
['c33', 500, 6287], ['c40', 1100, 7099], ['c34', 1000, 6993], ['c41', 
1900, 8099], ['c32', 100, 5896], ['c38', 700, 6599], ['c45', 800, 7839], 
['c43', 1300, 7943], ['c42', 300, 8442], ['c47', 1800, 9240], ['c44', 400, 
7837], ['c46', 300, 7739]]"

enter image description here

bw13300
  • 11
  • 1
  • 2
  • 1
    Does this answer your question? [How do I split the definition of a long string over multiple lines?](https://stackoverflow.com/questions/10660435/how-do-i-split-the-definition-of-a-long-string-over-multiple-lines) – buran Sep 01 '22 at 06:11

2 Answers2

1

" does not span for multi-line.

You need to use """ for spanning strings over multiple lines.

It should be the following:

line = """48,[['c0', 700, 2401], ['c1', 300, 2002], ['c2', 100, 1803], ['c3', 900, 
2604], ['c4', 200, 1905], ['c5', 700, 2406], ['c8', 1200, 2909], ['c11', 
600, 2312], ['c14', 400, 2115], ['c28', 500, 2229], ['c29', 300, 2030], 
['c31', 1200, 2932], ['c35', 1600, 3336], ['c36', 1700, 3437], ['c39', 
300, 2040], ['c13', 800, 3215], ['c17', 1600, 5230], ['c15', 1600, 5229], 
['c19', 1100, 4335], ['c10', 1500, 3513], ['c22', 900, 4535], ['c9', 1800, 
3715], ['c18', 900, 4532], ['c7', 1000, 3612], ['c12', 500, 3117], ['c16', 
700, 4329], ['c6', 500, 2913], ['c20', 1400, 4334], ['c30', 1200, 5763], 
['c25', 1500, 5860], ['c27', 700, 5958], ['c26', 900, 6157], ['c24', 1800, 
7054], ['c23', 500, 5753], ['c21', 1200, 3534], ['c37', 300, 7392], 
['c33', 500, 6287], ['c40', 1100, 7099], ['c34', 1000, 6993], ['c41', 
1900, 8099], ['c32', 100, 5896], ['c38', 700, 6599], ['c45', 800, 7839], 
['c43', 1300, 7943], ['c42', 300, 8442], ['c47', 1800, 9240], ['c44', 400, 
7837], ['c46', 300, 7739]]"""
Jeril
  • 7,858
  • 3
  • 52
  • 69
1

You can just combine seperate lines together with either \ or + \. But you need to treat every line as a string. Also be careful, so there is no whitespace after the backslash:

line = "48,[['c0', 700, 2401], ['c1', 300, 2002], ['c2', 100, 1803], ['c3', 900," + \
"2604], ['c4', 200, 1905], ['c5', 700, 2406], ['c8', 1200, 2909], ['c11', " + \
"600, 2312], ['c14', 400, 2115], ['c28', 500, 2229], ['c29', 300, 2030], " + \
"['c31', 1200, 2932], ['c35', 1600, 3336], ['c36', 1700, 3437], ['c39', " + \
"300, 2040], ['c13', 800, 3215], ['c17', 1600, 5230], ['c15', 1600, 5229], " + \
"['c19', 1100, 4335], ['c10', 1500, 3513], ['c22', 900, 4535], ['c9', 1800, " + \
"3715], ['c18', 900, 4532], ['c7', 1000, 3612], ['c12', 500, 3117], ['c16', " + \
"700, 4329], ['c6', 500, 2913], ['c20', 1400, 4334], ['c30', 1200, 5763], " + \
"['c25', 1500, 5860], ['c27', 700, 5958], ['c26', 900, 6157], ['c24', 1800, " + \
"7054], ['c23', 500, 5753], ['c21', 1200, 3534], ['c37', 300, 7392], " + \
"['c33', 500, 6287], ['c40', 1100, 7099], ['c34', 1000, 6993], ['c41', " + \
"1900, 8099], ['c32', 100, 5896], ['c38', 700, 6599], ['c45', 800, 7839], " + \
"['c43', 1300, 7943], ['c42', 300, 8442], ['c47', 1800, 9240], ['c44', 400, " + \
"7837], ['c46', 300, 7739]]"

The suggestion of using triple quotes (""") for a literal string is dangerous, as this adds linebreaks into your string. Because your variable is called line, I assume that is not what you want.

Jeanot Zubler
  • 979
  • 2
  • 18