I am using Python3 sqlalchemy to do some sql query, the code look like this:
def select(self) -> any:
with dict_session_scope() as local_session:
word = None
try:
word = local_session.query(Dict) \
.filter(Dict.demo_sentence == 0) \
.limit(5) \
.all()
except SQLAlchemyError as e:
local_session.rollback()
logger.error("query dict word error", e)
finally:
local_session.close()
return word
I was wonder is it possible to avoid add a slash \ in each lambda expression end. if I write the code with one line, sometimes it is too long and hard to read, if I wrap to multiline, I have to add the \ and make the code look like ugly. is it a perfect way to avoid the puzzle?