python實現類似C C 的條件編譯

2021-10-07 08:29:26 字數 557 閱讀 4485

python中的乙個內建常量__debug__,該常量預設是true,但是在執行python指令碼時加上-o會那麼該變數就為false。利用這個變數可以完成類似c/c++的條件編譯

example:

"""example.py"""

if __name__ ==

"__main__":if

not __debug__ :

print

("this is a debug test"

)else

:print

("this is a usual test"

)

..$ python3 example.py

this is a usual test

..$ python3 -o example.py

this is a debug test

儘管有點麻煩,還是能完成測試。

WPF中的實現類似Excel的動態條件格式

條件格式是excel乙個非常常見的功能,所謂動態條件格式,也就是根據資料庫的內容,動態的為每個單元格設定格式樣式而已。本文主要討論如何在wpf的網格應用程式中開發實現這一功能。componentone studio for wpf中的網格控制項c1flexgrid有乙個叫cellfactory的類,...

類似條件式的選擇

div id 選擇所有含有id屬性的div元素 input name keleyicom 選擇所有的name屬性等於 keleyicom 的input元素 input name keleyicom 選擇所有的name屬性不等於 keleyicom 的input元素 input name keleyi...

類似條件式的選擇

div id 選擇所有含有id屬性的div元素 input name keleyicom 選擇所有的name屬性等於 keleyicom 的input元素 input name keleyicom 選擇所有的name屬性不等於 keleyicom 的input元素 input name keleyi...