How do you implement “#ifdef” in python?

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

    Here is an example that I use to distinguish between Python 2 & 3 for my Python Tk programs:

    
    import sys
    if sys.version_info[0] == 3:
        from tkinter import *
        from tkinter import ttk
    else:
        from Tkinter import *
        import ttk
    
    """ rest of your code """
    

    Hope that is a useful illustration.

提交回复
热议问题