How do you implement “#ifdef” in python?

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

    If you're working on Spyder, you probably only need this:

    try:
        print(x)
    except:
        #code to run under ifndef
        x = "x is defined now!"
    #other code
    

    The first time, you run your script, you'll run the code under #code to run under ifndef, the second, you'll skip it. Hope it works:)

提交回复
热议问题