For the following construct what can the more pythonic way?
If it were C 开发者_Python百科I could just use ! but what is it equivalent in Python?
file_path = # something
if os.path.exists(file_path):
pass
else:
file_path = # make new path
file_path = # something
if not os.path.exists(file_path):
file_path = #make new path
Python Docs - Expressions - 5.1 Boolean Expressions
The not keyword.
if not os.path.exists(file_path):
file_path ...
Simply:
file_path = # something
if not os.path.exists(file_path):
file_path = # make new path
Operator not is also in C++, btw, as a synonym for !.
加载中,请稍侯......
精彩评论