def _get_session ( ) : session = getattr ( g , '_session' , None ) if session is None : session = g . _session = db . session ( ) return session
accessing a session in python
Return ( and memoize ) a database session
def _get_session():
    """Return (and memoize) a database session"""
    session = getattr(g, '_session', None)
    if session is None:
        session = g._session = db.session()
    return session