I stumbled upon this apparently horrific piece of code:
def determine_db_name():
if wallet_name in "":
return "wallet.dat"
else:
return wallet_name
What is supposed if xx in "":
to mean? Doesn't it always evaluates to False
?
It'll return True
if wallet_name
is itself empty:
>>> foo = ''
>>> foo in ''
True
It is horrific though. Just use if not wallet_name:
instead, or use or
and do away with the if
statement altogether:
def determine_db_name():
return wallet_name or "wallet.dat"
which works because or
short-circuits, returning wallet_name
if it is not the empty string, otherwise "wallet.dat"
is returned.
That expression is true if wallet_name
is the empty string.
It would probably be clearer if the code had been written as follows:
if wallet_name == '':
Or just:
if not wallet_name:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With