Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #32862

Re: How to specify a field name dynamically

Date 2012-11-06 22:36 -0500
From Dave Angel <d@davea.name>
Subject Re: How to specify a field name dynamically
References <BLU0-SMTP16867F87DDEABBC5B1BAA40F36A0@phx.gbl>
Newsgroups comp.lang.python
Message-ID <mailman.3352.1352259408.27098.python-list@python.org> (permalink)

Show all headers | View raw


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
arguments.

-- 

DaveA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: How to specify a field name dynamically Dave Angel <d@davea.name> - 2012-11-06 22:36 -0500

csiph-web