Timon
Timon

Reputation: 327

How to wrap lines automatically in Python Spyder?

I'm new to Python. I'm using Spyder 4.0.1, Python 3.7. The Spyder built-in PEP-8 convention code style check returns error E501 (line too long). Although I set the vertical line and wrap lines, it still shows error for the long characters line. Pycharm would wrap lines automatically, but I cannot find any effective solution in Spyder. What should I do? Do I have to press Enter manually for the long line? Thanks.

Upvotes: 14

Views: 19847

Answers (4)

Braveheart
Braveheart

Reputation: 21

I see two options available here, where the options within tools or right clicking (depending on the version of spyder you are using) allows the user to select wrap lines. For now we will call it display wrapping, and automatic line breaking.

With this enabled it does indeed wrap the display line, but it DOES NOT wrap to a new line number and automatically take care of indents, commas, etc. When it wraps, but does not add a line number, we will call this display wrapping, as shown below.

Showing a display line wrap.

Yet what I was looking for, and what I think the author was looking for was automatic line addition or automatic line breaking, similar to the image below.

Showing two lines on how one would hope line wrap or break is implemented.

In an older version of spyder, I think there was an option, where the line breaks were enforced (I could be misremembering and thinking of PyCharm). It seems this is only corrected if one chooses to apply code formatting on save (or by selection and right click menu), again see below.

Spyder6 Option for Automatic Code Formating on Save

Automatic Line Breaking as an option alongside the display wrapping would be very nice. If I missed this option somewhere, please let me know.

Upvotes: 0

Vatsal Shah
Vatsal Shah

Reputation: 1442

In Windows Go To Tools->Preferences->Editor and select Wrap lines.

enter image description here

Upvotes: 12

Kailey
Kailey

Reputation: 321

If you use mac, you need to go to Python on the left right corner then click on Preferences. enter image description here


Then go to Editor, and check Wrap lines. enter image description here

Upvotes: 9

Gaurav Kulkarni
Gaurav Kulkarni

Reputation: 220

To turn on the Word Wrap feature, go to View > Toggle Word Wrap or click the Edit Display icon in the Code Editor toolbar (it's the second-to-last one on the right) and select Toggle Word Wrap. You can also set the program preferences to keep this feature on by default.

Upvotes: 1

Related Questions