Search code examples
pythonpycharm

hotkey/hotstring to print last variable/all defined variables in PyCharm?


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


Solution

  • 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()])
    

    enter image description here

    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