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
preguntado el 08 de noviembre de 11 a las 13:11
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:
if song != True: raise ValueError
if song == Null: raise ValueError