0

Consider the following list that breaks across lines:

a = [1, 2, 3, 
     4, 5, 6]

When I run this directly from the editor in Spyder, I get: SyntaxError: unmatched ']'

If I move the whole expression to the same line, there is no error.

If I run the same code (with the line break) from a Jupyter notebook, there is no error.

If I develop this code directly from the IPython console, it leads me with '...:' and there is no error.

Are there any good practices or settings for implementing line breaks when writing scripts in Spyder?

Thanks so much in advance.

Jeff
  • 23
  • 7
  • Does this answer your question? [How can I do a line break (line continuation)?](https://stackoverflow.com/questions/53162/how-can-i-do-a-line-break-line-continuation) – m13op22 Sep 08 '21 at 21:15
  • @m13op22 be aware that many of the answers were written before the style guide change, and are now considered non-idiomatic. – Peter Wood Sep 08 '21 at 21:25
  • That shouldn't be an error. Can you give more details? See how to create a [mcve]. – Peter Wood Sep 08 '21 at 21:26
  • Thanks so much all. See my comment below. – Jeff Sep 09 '21 at 01:32

1 Answers1

0

You can use a explicit line break: \

a = [1, 2, 3, \
     4, 5, 6]

Reference Here.

Zichzheng
  • 1,090
  • 7
  • 25
  • 1
    But you shouldn't need it. – Peter Wood Sep 08 '21 at 21:23
  • Hi all, thanks so much for the responses. @Peter Wood, you are right. This isn't actually an error. It had to do with the keyboard shortcut I was using to run the code directly from the script. Apologies. I am an R user and erroneously adapted a code execution approach. Just getting used to Python. – Jeff Sep 09 '21 at 01:28