Dynamic function docstring

前端 未结 3 1824
闹比i
闹比i 2020-12-20 13:53

I\'d like to write a python function that has a dynamically created docstring. In essence for a function func() I want func.__doc__ to be a descri

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-20 14:22

    Instead of messing with the function, why not write your own help function?

    my_global=42
    
    def help(func):
        print('%s: my_global=%s'%(func.func_name,my_global))        
    
    def foo():
        pass
    
    help(foo)
    

提交回复
热议问题