How do you implement “#ifdef” in python?

前端 未结 8 2040
广开言路
广开言路 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:41

    As far as I am aware, you have to use actual if statements. There is no preprocessor, so there is no analogue to preprocessor directives.

    Edit: Actually, it looks like the top answer to this question will be more illuminating: How would you do the equivalent of preprocessor directives in Python?

    Supposedly there is a special variable __debug__ which, when used with an if statement, will be evaluated once and then not evaluated again during execution.

提交回复
热议问题