How do I handle fieldnames in Metakit 2.0

Jean-Claude Wippler jcw at equi4.com
Fri Mar 10 05:32:51 EST 2000


Anders,

[...]
> I have a database table with about 20 columns so I created a list
> which contains all the names for the columns.
> flist = ['name','email']
> 
>  But I can't use these names in the call to Metakit.
> 
> if I want to add a record (row) then I use the
> vw.append(name='Anders',email='ame at swipnet.se')
> 
> but if I want to build this statement dynamicle How do I do it. The
> column names (name, email) isn't a string and the whole expression
> (within the parenteses) isn't a string...
> 
> The best I can do is create a string that looks like
> str = "name='Anders',email='ame at swipnet.se'"
> but that wont work in vw.append(str)

Append also accepts dictionaries, sequences, or objects with attributes:

dict = {'name':'Anders', 'email':'ame at swipnet.se'}
vw.append(dict)

list = ['Anders', 'ame at swipnet.se']
vw.append(list) # assuming the view is defined in the same order

class Dummy: pass
item = Dummy()
setattr(item, 'name', 'Anders')
setattr(item, 'email', 'ame at swipnet.se')
vw.append(item)

Or you can append an empty row and then set its properties:

n = vw.append()
setattr(vw[n], 'name', 'Anders')
setattr(vw[n], 'email', 'ame at swipnet.se')

-- Jean-Claude



More information about the Python-list mailing list