I have a method that do a sql-query and return a value. If empty it raise an exception. The code works as expected but it seems like there’s a more clean way to do it? Or is it?
def get_song(self, number):
db_cursor.execute("select * from songs where Id = ?", number)
song = db_cursor.fetchone()
if song:
return song
else:
raise ValueError
As the True statement doesn’t improve your code (you just want to be assured it is not False) you could preserve some lines doing so:
or