2011-08-04 97 views
1

對於下面的構造什麼可以更pythonic的方式?相當於Python的! operator

如果它是C我可以只使用!但它在Python中等價嗎?

file_path = # something 
if os.path.exists(file_path): 
    pass 
else: 
    file_path = # make new path 
+1

使用python語法,它經常用於嘗試簡單的英語! – wim

回答

0

只需:

file_path = # something 
if not os.path.exists(file_path): 
    file_path = # make new path 

not也是在C++中,順便說一句,作爲用於!的同義詞。

1

not關鍵字。

if not os.path.exists(file_path): 
    file_path ...