Re: How to specify a field name dynamically

Discussion in 'Python' started by Dave Angel, Nov 7, 2012.

  1. Dave Angel

    Dave Angel Guest

    On 11/06/2012 10:14 PM, jack wrote:
    > I have three tables:

    What's a table? I'll assume you're using Python, but what version, and
    what extra libraries do you have installed ? At least show your import
    statements, so we might have a chance at guessing. I'll assume the db
    stands for database, but what database, or what library??? if it really
    is a database question, and you specify what library you're using, then
    maybe somebody who uses that will jump in.

    > table1
    > |———————|
    > | id | f1 |
    > |———————|
    > table2
    > |———————|
    > | id | f2 |
    > |———————|
    > table3
    > |———————|
    > | id | f3 |
    > |———————|
    > I want define a function to insert records to someone,but I don't know
    > how to specify a field name dynamically.
    > I had a try like this
    > / def insert_record(table, field, goods)://
    > // return db.insert(table, field=goods//)/
    > or
    > / def insert_record(table, **kv)://
    > // return db.insert(table, **kv)/
    > but it does not works

    That's not much of a clue. Do you mean you get an exception? If so,
    paste it into a message, the full traceback. Or you mean it returns the
    wrong data? Or it crashes your OS?

    My first guess would be that those slashes are causing syntax errors.
    But if that's a bug in your OS's copy/paste, then I'd say you have
    indentation problems. Or maybe these are not just functions, but methods
    inside a class. And in that case, I might guess that you're missing the
    self argument, and therefore getting an exception of wrong number of


    Dave Angel, Nov 7, 2012
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page