Reputation: 501
In Intellij for java I can type soutv +
tab and it will expand it to
System.out.println("var1 = " var1 ", var2, " = ", var 2)
etc.
Is there someting equivalent in PyCharm for python?
A hotstring that I type so it automatically creates something like
print("var1=", var1, ...)
?
(in IntelliJ for java there is also sout, soutm, soutp etc.. again: equivalent in PyCharm for python?)
Upvotes: 4
Views: 200
Reputation: 3756
It is actually quite possible to define a Live Template with the equivalent of soutv for Python. I call mine printv
.
Live Template
from the dropdown menuprintv
Like soutv, but for Python
,print('$EXPR_COPY$:',$EXPR$)
EXPR_COPY
line highlighted, click the down arrow to move this line down below EXPR
EXPR_COPY
's Expression field, enter escapeString(EXPR)
.
It should now look like this:
Now type printv
and press the tab key to enable the template. It should behave just like soutv
, but for Python.
JetBrains provides documentation on live templates that defined the escapeString(...)
function used here. Another answer provided the EXPR_COPY
and EXPR
variable names.
Upvotes: 2
Reputation: 8572
All of this is live templates.
I believe, the difference is that all python is runtime, so you can't really build namespace/scope while writing the code. What you can do, tho, is to create live template like this:
print([f'{name} = {value}' for name, value in locals().items()])
Now you can use plocals
+ tab to insert line of code that will print out all variables in local scope
Note: formatting is for py 3.6+, but that's just for illustrative purposes
Upvotes: 2