Python IDLE (2.7): multi-tabbing not working - python

I'm having a problem with the Python IDLE. If I try to tab in multiple lines (Mark lines+Press [Tab]) it just replaces the lines, and doesn't tab them in. If I try to tab the out (Mark lines+Press [Tab+Shift]) the region will turn white while marked. If I try to tab in a single line (Press [Tab]) it tabs way too far (modified 5 spaces, tabs about 20). If I try to tab out a single line (Press [Tab+Shift]), nothing happens. Is there another one having this issue, or an idea to fix it?
Caps and Numlock didn't change anything.

To tab (indent) multiple lines in IDLE use CTRL + ] (The ] key on the keyboard) .
To tab them in the other direction (to decrease the indentation - dedent) , use CTRL + [ . .

Related

Comment/Uncomment multiple lines in JupyterNotebook hotkey

I was wondering, if there is a PRO way of commenting/removing multiline # comments in JupyterNotebooks.
# line1
# line2
# line3
Something like SHIFT + " for adding triple quotes.
CTRL+/ for comment and uncomment multiple lines
you can press 'h' anywhere in command mode, you can find all the shortcuts of jupyter.
For the big bunch of people that does not use an english keyboard, probably the adequate keys are in other place.
In the case of a Spanish Keyboard, I can comment/uncomment lines using "Ctrl + }"
On a German keyboard layout I use CMD + ? successfully.
For those with a Portuguese keyboard and Windows operating system, CTRL + ~ comments multiple lines.

Keyboard shortcut to comment code in Thonny IDE

Whats is the keyboard short cut to comment single line of code and slsected lines of code in Thony IDE for python?
Ie, The Thony equivalent of ctrl + / in VS Code
Single line comment.Ctrl + 1.
Multi-line comment select the lines to be commented. Ctrl + 4.
Unblock Multi-line comment. Ctrl + 5.
To comment single line:
Put a cursor on the line which you want to comment. Press Alt+3 to comment, Alt+4 to un-comment.
To comment single line:
Select the desired lines of code to comment. Follow same keys i.e. press Alt+3 to comment, Alt+4 to un-comment.
Note:
For further shortcuts, please click on Edit menu option next to File and you'd see various shortcuts available in Thonny IDE.
Use Ctrl+3 for toggling between "commented" and "uncommented".
Use Alt+3 to comment.
Use Alt+4 to uncommment.
(Screenshot)
If you want to change the default shortcuts, you can follow the instructions on this official github-page:
https://github.com/thonny/thonny/wiki/Custom-shortcuts
With the latest update of Thonny IDE you can do
ctrl + 3
for both single line and multiline commenting and uncommenting.

Hitting tab is producing a "0" instead of four spaces only on one line in Sublime Text 2

I am very new to programming and using Learn Python The Hard Way. I'm using Sublime Text 2 and haven't had any problems yet. Normally to comment I will hit tab a few times after the line of code to line up the comments on the right. It always works except for the following line.
print "OR, we can use variables from our script:"
amount_of_cheese = 10
amount_of_crackers = 50
When I hit tab after amount_of_cheese = 10 it just adds zeros. I hit tab twice and it became
amount_of_cheese = 1000
If I keep hitting tab it will delete the last 0 and so on switching from 100 to 1000.
Every other line tabs out fine after the code.
I'm sure this is basic but it is just strange. What's the problem?
I just tested this out. If you have the numbers 100 or 1000 somewhere else in your file, then typing 10 then TAB is going to act like tab completion. If you type a space then tab it should work.

Python indentation on notepad++

Every time I write a function in notepad++ it won't indent for me even when I'm pretty sure I have auto-indent selected. I then manually do 4 spaces and do two print commands but it's not working. It says 'unexpected indent' in Powershell. Here's what I'm using:
def print_twice():
print "hi"
print "hi"
print_twice()
You can set your notepad++ to always convert tabs to whitespace, or to show whitespace characters. Please see answers in this question
On your notepad++, go to Settings> Preferences > Tab Settings and Check "replace by space" making sure "tab Size" is set to 4.
This has worked for me.
In Notepad++, Go to Settings>>Preferences. In the dialog box that will appear select Tab Settings, check the 'Replace by space' checkbox. You can alter the number of spaces by clicking on the Tab space: 4 link (whereby the existing tab space is 4 spaces). Close the dialog box. That is it.
Just in case if you dont see 'tab settings' Under "Preferences", as myself, then you just need to look for.
Notepad++ > Settings > Preferences > language > Tab settings

Is there a quick way to decrease the indentation of multiple lines in Python?

I am a newbie to python programming. I find that decreasing the indentation of a block of codes in python is quite annoying. For example, given the following code snippet
for i in range(density):
if i < 5:
x, y = rnd(0,shape[1]//2)*2, rnd(0,shape[0]//2)*2
Z[y,x] = 1
....
....
If I comment the if statement, I have to decrease the indentation for lines in the if block one by one, is there a way that I can do this by one key stroke as I increase the indentation of a block of codes by selecting them and press the TAB key? I guess this is environment dependent, so could you please provide solutions to do so in Eclipse+Pydev, VIM, and other common editors?
In vim, you select the block and then press the < key.
In Eclipse you select it and then press SHIFT + TAB.
Every code editor worth its salt has a one-key way to indent and dedent blocks.
You could also replace the if statement with:
if True: # if i < 5:
and leave everything else alone - no indent/dedent to undo later.
Perhaps late for your case, but if useful for others:
SHIFT + TAB will do unindent for the selected text in Eclipse.
Use Preferences-Pydev-Editor settings uncheck change tabs to spaces. It makes detent errors and your problem. And test other options like 4 space tab, 8 space tab and so on.

Categories