new to python and spyder here.
Is there a way to autocomplete brackets in spyder?!
Also is there a way to get auto indentation?
I risk making this too broad but is there also a way to make sure that if say I'm defining a function, I can simply click at the end of the function without highlighting everything to make it run.
Example:
def print_twice(Spam):
print(Spam)
print(Spam)
In the above I would like to run the last line but have spyder run everything from def print_twice(Spam) to print(Spam)
Thanks and sorry if the question is annoying or already has an answer. Couldn't find it.
(Spyder maintainer here) My answers:
Is there a way to autocomplete brackets in spyder?
Brackets are auto-completed automatically by default.
Also is there a way to get auto indentation?
Auto-indentation works automatically too, after : or by aligning your code on open parenthesis.
is there also a way to make sure that if say I'm defining a function, I can simply click at the end of the function without highlighting everything to make it run[?]
No, but you can create a cell to run your function. Cells are regions in your code delimited by comments of the form # %% and you can run them with Ctrl+Enter (run cell and stay on it) or Shift+Enter (run cell and advance to next one).
Related
I am having a problem in PyCharm (2022.3.1) that the variables of my code are not showing in the right-bottom area of "Variables" in Python Console in PyCharm.
This function is extremely useful when coding. You can keep track of the changes and data-type of your variables.
How to solve it?
The problem mentioned was solved and I will described, here, how to do it:
I ran a simple code with two variables. The code runs fine but the variables do not show (in the red circle area, as they should be).
Se this first first screenshot
If I add a new variables manually in the Python Console it will show in the variable area as it shows
So how did I solve this issue?
You will need to change the Debug configurations as shown here, and check the box "Run with Python Console", then Apply, Ok.
After that when you run your code, your variables will be shown in the variables tab at the bottom-right-corner, as shown here.
After that you will also be able to type new variables in the Python Console and they will immediately be shown in the variable tab.
I am not able to click(I can say it's diabled) step in, step out, step over option in pycharm debugger
I don't know if this is exactly what is causing your issues but here is one possibility:
All debugging options are grayed out in the menu if your cursor is on an empty line or a line that is a comment. Try putting your cursor on an actual line with code. The "Toggle Line Breakpoint" option in the "Run" menu should now become active. After starting the script with "Run -> Debug", the breakpoint will be triggered (assuming the code reaches it) and the other debug options such as "Step over" become available.
As mentioned in this answer: https://stackoverflow.com/a/48665161/2891209
Depending on what you're trying to debug it is possible for step-in to not show you code which isn't pure python. Pycharm will do the best it can of course, but if the function you're trying to debug isn't native python be prepared for anything...
If you're trying to step into a python wrapped C library function
Sometimes the debugger will skip over that code completely.
Sometimes you can walk the frames but the editor can't show you lines of code.
Sometimes you'll be able to step into an empty skeleton of a function.
It really depends on how the library was created.
Most of the time, Intellisense on VSC is really convenient, pressing 'enter' to autocomplete variables, functions etc. So I don't want to get rid of it completely.
But I find it INCREDIBLY jarring when I'm closing parentheses, pressing enter, and the autocomplete always suggests and enters one of these two useless snippets of codes:
import pdb; pdb.set_trace()
(the same thing happens here trying to import pandas as pd)
or
root = tk.Tk()
I want to keep autocomplete upon pressing enter ON for things like variables and function suggestions, and preferably remove the above from the suggestions altogether if possible. Is there a way to do this?
If it is a code snippet that gets applied here, you can use the editor.snippetSuggestions in your settings and set it to none if you want to hide snippets from intellisense.
You can also modify the sorting of the suggestions though if it helps in your specific usecase. more details can be found here: https://code.visualstudio.com/docs/editor/intellisense#_snippets-in-suggestions
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.
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.