爲什麼我不能這樣做?Python中的布爾運算符
extout = os.path.splitext(args.outputfile)[1].lower()
if extout != (".csv" | ".xml"): # <------- creates error
sys.stderr.write('ERROR: Invalid extension or none found. This program only recognizes .csv or .xml extensions %s\n')
sys.exit(1)
這給了我一個錯誤類型:
Unsupported operand types for |: 'str' and 'str'
這是正確的答案,和Pythonic。 – Tadeck
根據Python 3.2中的[optimizations](http://docs.python.org/3.4/whatsnew/3.2.html#optimizations),你應該寫'如果extout不在{「.csv」,「.xml 「}:'而不是。 –