Adding Macros to Python

前端 未结 7 1162
无人及你
无人及你 2021-02-02 07:41

I would like to invoke the following code in-situ wherever I refer to MY_MACRO in my code below.

# MY_MACRO
frameinfo = getframeinf         


        
7条回答
  •  南旧
    南旧 (楼主)
    2021-02-02 08:29

    you could use function if you wanted to:

    def MY_MACRO():
        frame = currentframe()
        try:
            macro_caller_locals = frame.f_back.f_locals
            print(macro_caller_locals['a'])
    
        finally:
            del frame
    
    def some_function:
        a = 1
        MY_MACRO()
    

提交回复
热议问题