Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Is there any keyboard shortcut for line comment in pythonista ?.
-
Hello,
I'm learning Python at my online class.
Pythonista is must-have tool for my class.
I'm using Pythonista in my iPad using bluetooth external keyboard.
I read documents of pythonista, but can't find keyboard shortcut for comment.
Is there any keyboard shortcut for line comment in pythonista?
If it is, what is it?thanks
jackyjoy -
@alexsunnyx123 why do you want a shortcut, an # at the begin of the line sets it as comment
-
@alexsunnyx123, there is no keyboard shortcut in the product. People have used their own scripts to add a shortcut in the past. An example of commenting the current line by code is in the Pythonista docs, and I think you can add a shortcut for an external keyboard, but do not have the code handy.
-
This post is deleted! -
@alexsunnyx123 please check this
-
I use the following method to comment out code using the keyboard. It works on single and multiple lines and you don’t need to select the whole line to comment it out.
I used the examples provided with Pythonista to create an extension script:
import editor, console script = editor.get_text() sel_start, sel_end = editor.get_line_selection() selected_text = script[sel_start:sel_end].splitlines() r = '\n'.join('#' + i for i in selected_text) editor.replace_text(sel_start, sel_end, r)
From there, you can add the script as an IDE extension:
click the wrench icon at the top-right of the window. The bottom section of the popup menu that appears is reserved for extensions. Click “Edit” then the “+” icon and browse and add the script you created in the previous step.You can comment out lines by selecting the wrench icon and clicking the newly added icon. You can also run the extension using your keyboard if it has the Apple “Command” and “Option” keys available. Hitting Command + Option + a number on the keyboard will trigger that script. So if the extension you added is the only extension script in your IDE, you would hit Command + Option + 1.
It should only take a few minutes to set up and then you’re good to go.