How to wrap lines automatically in Python Spyder? - python

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.

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

If you use mac, you need to go to Python on the left right corner then click on Preferences.
Then go to Editor, and check Wrap lines.

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.

Related

python extension for vs code

I have a problem with python autocomplete in visual studio code. The only way I can trigger the autocomplete function is with the Tab or Enter key. Brackets and dot does not have any effect (or better it just hides the suggestion box and puts the bracket in place on the unfinished word e.g. -> typing pr in the editor would display the suggestion box with print as the first choice, if i then press bracket i end up with pr() instead of print())
I presume there should be some settings so autocomplete would act "normally" but I can't find it.
This is set by the shortcut key. Open the Default Keyboard Shortcuts (File > Preferences > Keyboard Shortcuts) and search for "acceptSelectedSuggestion". You will see that there are only two settings by default, the Tab and Enter keys.
If you want to add other buttons to trigger typing intellisense, right-click on one of the settings and select Add Keybinding,
then press the button you want to set, and press Enter to save.
I think you don't need to use the python autocomplete extension. You can just use the Python extension.
Tab or enter is required to actually make a selection. Otherwise, you could have custom function printStuff, and typing pr( would not necessarily pick the right one.
From what I can tell, PyCharm works the exact same way, so unclear what "acts normal" means in this context.

Spyder Python Shortcut to Select All Text Above Current Line

Let's say I'm on line 500 in spyder, and I want to run everything from that line and above (lines 1-500), is there a shortcut to select the lines quickly. Right not I'm highlighting the lines and scrolling up and using shift and up arrow but both of them take some time to scroll. Is there a faster way to select, similar to select all but only for the specific lines 1-500?
(Spyder maintainer here) The easiest way to do what you want is by creating code cells. These are sections in your file separated by comments of the form # %%, which can be run independently by placing the cursor inside them and pressing the shortcuts Ctrl+Enter (run cell) and Shift+Enter (run cell and and advance to the next one).
Please refer to our documentation for more details.
This post is old I know, but I found out that CTRL-Shift-Home doesn't work for me.
I have to use CTRL-Alt-Shift-Home to select everything above the line or -End for everything below.
This is for Windows 7 and Spider 3.3.6
Just in case someone is interested in deleting all the lines, and only find this question after searching, the easy way would be using
'''
for all the codes between the two lines, and then use the triangle on the left to suppress, so you could delete in one go.

Copy/Paste from Python command line to sublime

Apologies in advance for what should seem obvious to me...
New to Python, but other wise very experience, hence the frustration.
As I'm learning, I'm attempting to prototype the command at the command prompt (">>>") as I script. I can enter the python commands and validate they are correct, but (currently) then have to retype the command in to sublime, which seems inane, especially as I'm watching videos where they are copying and pasting one to the other...
Windows 7 CMD, & Python ">>>" command lines, Sublime window
I'm trying to copy commands from the Python command line ">>>" to the sublime editor in an open/new tab. Normally, I would mark/highlight the selection, then Ctrl+c, place the cursor in the target window (sublime in this case), Ctrl-v, and be done.
However, I'm unable to select what I want to copy (??). Up/down arrows will recall the individual lines (no problem with that) -- where I would usually do a Ctrl-(left/right arrow) to select the text, but no indication that anything has been selected. Same result using the mouse.
Thanks in advance for the assist.
This is an oddity of the Windows command prompt. First, there is a little bit of setup. Then you can do the cut-and-paste in a slightly different way than you are used to.
Setup
Right click on the title bar at the top. Select "Properties". Click on the "Options" tab. Make sure that the "QuickEditMode" box is checked. Close the Properties window.
Cut-and-paste should be enabled, but not using control-C to cut. Select the text you want to copy. Instead of typing control-C, just hit return (with the desired text selected). The text should now be on the clipboard to paste into other applications (with control-V)
In Linux terminals, pressing Ctrl+k copies everything in the line that follows the cursor. Ctrl+u copies the everything before the cursor.

Pound sign a bunch of code at once in psychopy for mac

this is a very basic question, but is there a way to put '#' next to a highlighted bunch of code in psychopy for mac?
Edit: if you are using psychopy for mac you can press ctrl-' to input, ctrl-shift-' to remove.
Like the comments said, this is an editor issue and not a Python programming question. The closest thing there is to a "standard Python editor" is probably the one built into Idle, the IDE that comes with every CPython distribution. There, you can
Highlight the lines you want to comment out
Use Format>Comment Out Region from the menu or press Alt+4 at a PC keyboard.
This works in the module editor, not the shell, and uses a double pound sign as a hint that the lines were commented-out in a block operation.
Any editor with regular expression search and replacement and also with a "replace all within selection" option will work, too. Just highlight the lines and change all occurrences of ^ to # within that selection.

indent with 'tab' button in python commandline

hi everyone :)
my problem is, up until now, i have exclusively used tabs to indent python, as i find it easier than spaces, but for no reason i know, python interactive prompt, the basic python.exe one, suddenly refuses to accept the tab button, all it does is flash the cursor. all i can think of is that my computer in suddenly treading the window like any other, using tab to cycle input things, in this case the single one. also, before now, i could use the up button to reach previously typed code, the if i submit that line with no changes, use the down button to access the line that came after it, but now up works, but as if i had changed the line, eg moves me back to the "bottom" of the list of inputs, so down doesn't work.... my question simply is: how do i get my good old tab and down button to work like i want them to again? :(
thanks xxx
If you are using Windows with the standard cmd.exe console (and it would have been helpful for you to have stated this up front) then you can use the TAB and arrow keys exactly as you desire.
I recently observed this behavior too, on Windows, using cmd.exe. It also happens with Console2 - an alternate shell I sometimes use.
Though I do always use spaces in normal code in an editor, I had been accustomed to using the Tab key to indent in short multi-line inputs in the interactive python.exe interpreter. Recently that stopped working - pressing the Tab key flashes the cursor and doesn't indent. Using spaces does work fine here, though it's not as convenient past a couple of indentations.
I suspect (but am not certain) that the cause was installation of pyreadline or rlcompleter - I had been messing with trying to get tab completion in an interpreter in an embedded application on Windows. Of course in your case another installation could have included those packages.

Categories

Resources