Adding Macros to Python

前端 未结 7 978
无人及你
无人及你 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:34

    I'd say you should define a function to do this, since there are no macros in Python. It looks like you want to capture the current stack frame, which you could do simplify by passing in currentframe() from the call site to your shared function. Ditto with locals.

    def print_frame_info(frameinfo, locals):
        msg = 'We are on file ' + frameinfo.filename + ' and line ' +  str(frameinfo.lineno)
        current_state = locals.items()
    
    def some_other_function:
        some_function()
        print_frame_info(currentframe(), locals())
    
    0 讨论(0)
提交回复
热议问题