Python Macros: Use Cases?

后端 未结 17 2103
甜味超标
甜味超标 2021-01-30 18:37

If Python had a macro facility similar to Lisp/Scheme (something like MetaPython), how would you use it?

If you are a Lisp/Scheme programmer, what sorts of things do y

17条回答
  •  离开以前
    2021-01-30 18:54

    Coming from a C-world, I'd really appreciate being able to do efficient logging of rich messages. Instead of writing

    if logger.level > logger.DEBUG:
        logger.log('%s' % (an_expensive_call_that_gives_useful_info(),))
    

    with macros, one could instead do something like

    DEBUG('%s' % (an_expensive_call_that_gives_useful_info(),))
    

提交回复
热议问题