Generic function that accept a table and column name and returns all the primary key values that mat

Posted by nashr rafeeg on Stack Overflow See other posts from Stack Overflow or by nashr rafeeg
Published on 2010-05-10T08:04:09Z Indexed on 2010/05/10 8:14 UTC
Read the original article Hit count: 443

Filed under:
|

i have functions that look like this that is littered through out the code

def get_M_status(S): 
    M_id = merital.select(merital.c.marital_status_description == S).execute().fetchone()
    if M_id == None:
        print "Warning: No Marital id found for %s Merital status to Single" % S
        M_id = merital.select(merital.c.marital_status_description == "Single").execute().fetchone()       
    return M_id[0]

i was wondering if their is a way to write a generic function where i can pass the relevant values ie: table name primary key column filter column and filter value

cheers

© Stack Overflow or respective owner

Related posts about python

Related posts about sqlalchemy