Python Macros: Use Cases?

后端 未结 17 2284
甜味超标
甜味超标 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 19:03

    Well, I'd like instead of

    print >> sys.stderr, "abc"
    

    to write

    err "abc"
    

    in some scripts which have many debug printout statements.

    I can do

    import sys
    err = sys.stderr
    

    and then

    print >> err, "abc"
    

    which is shorter, but that still takes too many characters on the line.

提交回复
热议问题