How to elegantly check the existence of an object/instance/variable and simultaneously assign it to variable if it exists in python?

You want to execute a Exist query to be efficient

(ret, ), = Session.query(exists().where(SomeObject.field==value))

Mike Bayer explain it in his blog post:
http://techspot.zzzeek.org/2008/09/09/selecting-booleans/

You can use scalar if you don’t want to have a tuple as result:

ret = Session.query(exists().where(SomeObject.field==value)).scalar()

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)