How do you implement “#ifdef” in python?

前端 未结 8 2041
广开言路
广开言路 2020-12-02 17:04

Programming in C I used to have code sections only used for debugging purposes (logging commands and the like). Those statements could be completely disabled fo

8条回答
  •  既然无缘
    2020-12-02 17:34

    There is no direct equivalent that I'm aware of, so you might want to zoom-out and reconsider the problems that you used to solve using the preprocessor.

    If it's just diagnostic logging you're after then there is a comprehensive logging module which should cover everything you wanted and more.

    http://docs.python.org/library/logging.html

    What else do you use the preprocessor for? Test configurations? There's a config module for that.

    http://docs.python.org/library/configparser.html

    Anything else?

提交回复
热议问题