On 31 juil, 00:48, Jonathon Anderson <[EMAIL PROTECTED]> wrote: > With sqlalchemy, I find myself always spelling: > > instance = Entity.get(instance_id) > if not instance: > print "no record of an instance with id %s" % instance_id > else: > print instance
There's a load() method, and selectone() (depending on your needs) which try to load an object and raise an exception if it cannot find a result. Here is an example (using a Session object) : try: session.query(Entity).load(instance_id) # OR session.query(Entity).selectone(entity.c.id == instance_id) except InvalidRequestError: print "no record of an instance with id %s" % instance_id Hope it helps, - Jonathan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---