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


Groups > comp.lang.python > #32862 > unrolled thread

Re: How to specify a field name dynamically

Started byDave Angel <d@davea.name>
First post2012-11-06 22:36 -0500
Last post2012-11-06 22:36 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#32862 — Re: How to specify a field name dynamically

FromDave Angel <d@davea.name>
Date2012-11-06 22:36 -0500
SubjectRe: How to specify a field name dynamically
Message-ID<mailman.3352.1352259408.27098.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web