Python 3 print without parenthesis

前端 未结 8 1728
一整个雨季
一整个雨季 2020-11-30 01:27

The print used to be a statement in Python 2, but now it became a function that requires parenthesis in Python 3.

Is there anyway to suppress these par

8条回答
  •  温柔的废话
    2020-11-30 02:04

    Use Autohotkey to make a macro. AHK is free and dead simple to install. www.autohotkey.com

    You could assign the macro to, say, alt-p:

    !p::send print(){Left}
    

    That will make alt-p put out print() and move your cursor to inside the parens.

    Or, even better, to directly solve your problem, you define an autoreplace and limit its scope to when the open file has the .py extension:

    #IfWinActive .py            ;;; scope limiter
    :b*:print ::print(){Left}   ;;; I forget what b* does. The rest should be clear 
    #IfWinActive                ;;; remove the scope limitation
    

    This is a guaranteed, painless, transparent solution.

提交回复
热议问题