Good one Serbitar. Much better than my solution. When I saw your "I dont get it" post, I was reminded of why JavaScript functions return functions instead of values. So they can capture the scope too.
Now you have to call this every time you have to access this table, is that right? On Apr 10, 5:58 am, Serbitar <[email protected]> wrote: > OK got it. Lambda functions dont save their scope. > > Here is the right code: > > list = ["a","b","c","d"] > fields = [] > for entry in list: > fields += [Field(entry, type="string")] > db.define_table('test', *fields) > class MyVirtualFields(object): > pass > > def get_func(value): > def func(self): > return getattr(self.test, value) > return fun > > for entry in list: > setattr(MyVirtualFields, entry +"_", get_func(entry)) > > db.test.virtualfields.append(MyVirtualFields())

