Reputation: 13
For the following construct what can the more pythonic way?
If it were C 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
Upvotes: 1
Views: 203
Reputation: 72299
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 !
.
Upvotes: 0
Reputation: 43269
file_path = # something
if not os.path.exists(file_path):
file_path = #make new path
Python Docs - Expressions - 5.1 Boolean Expressions
Upvotes: 4