EsseTi
EsseTi

Reputation: 4271

PyCharm surround with "print"

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?

Upvotes: 8

Views: 1335

Answers (1)

tzot
tzot

Reputation: 95901

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).

Upvotes: 12

Related Questions