Is there a maximum size to a Python program?
John Machin
sjmachin at lexicon.net
Mon Apr 27 02:23:33 EDT 2009
On Apr 27, 2:34 pm, "Paul Hemans" <dar... at nowhere.com> wrote:
> entry = schema.BILLS()
> exists = session.query(schema.BILLS).filter(schema.BILLS.REFNO==u"1")
> if exists.count == 0:
> entry.REFNO = u"1"
> entry.THRDPTY = u"""C5"""
> entry.AMOUNT = 0
> entry.TIMESTAMP = 0
> entry.ALLOCATED = 0
Instead of generating code like that, you can do it dynamically. The
built-in setattr() function is your friend, e.g.
for col_name in col_names:
if needs_updating(col_name):
value = get_new_value(col_name)
setattr(entry, col_name, value)
> session.add(entry)
>
> session.commit()
> session.close()
Cheers,
John
More information about the Python-list
mailing list