Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyCharm surround with "print"

Tags:

pycharm

Pycharm has the function to "surround with" pieces of code. There are some already setted up functions:

enter image description here

I would like to add print() (using python3) to it, how can I do?

like image 681
EsseTi Avatar asked Nov 16 '16 10:11

EsseTi


People also ask

How to use live template PyCharm?

Press Ctrl+Alt+S to open the IDE settings and select Editor | Live Templates. Select the template group where you want to create a new live template (for example, other). If you do not select a template group, the live template will be added to the user group. and select Live Template.

How do I print values in PyCharm?

By default, PyCharm suggests to print the name of a file $FILE$ in the header and the current page number $PAGE$ of all pages $TOTALPAGES$ in the footer. The following print keywords are recognized: $FILE$ prints fully qualified filename. $PAGE$

What is live template PyCharm?

Live templates Last modified: 12 May 2022. Expand a live template: Tab. Configure: Ctrl+Alt+S Settings/Preferences | Editor | Live Templates. Use live templates to insert common constructs into your code, such as loops, conditions, various declarations, or print statements.

How do I run a current tab in PyCharm?

Shortcut: shift + control + F10.


1 Answers

AFAIU, you can define your own “Live” templates for this.

define the live template

Go to FileSettingsEditorLive Templates. In the right pane tree, click on Python then click the green “+” button on the right; select “Live Template”.

Enter a name for Abbreviation (e.g. “printer”), a Description, and then in the Template text:

print($SELECTION$)

Afterwards click on the “Define” of the “No applicable contexts. Define” line at the bottom. Select “Python” in the tree. This step is important!

use the live template

Now your template will be usable by the CodeSurround with Live Template action (in my case, the shortcut is Ctrl+Alt+J).

like image 122
tzot Avatar answered Oct 17 '22 18:10

tzot