[web2py] Re: Trying to use a variable as a field name in a table insert

2017-06-12 Thread Peter
> I don't think I said anything was "non pythonic" (I identified some *invalid > *code -- but that code literally doesn't work at all, it is not merely > non-Pythonic). > The above code was my suggested (working) alternative, and I think the use > of dictionary unpacking would be considered Py

[web2py] Re: Trying to use a variable as a field name in a table insert

2017-06-12 Thread Anthony
On Monday, June 12, 2017 at 2:11:12 PM UTC-4, Peter wrote: > > > Re: > What's wrong with this approach > db.payment_allocations.insert(**{'payment_ref': payment.id, > ref_field: record.id, > 'amount_allocated': allocation}) > > To be

[web2py] Re: Trying to use a variable as a field name in a table insert

2017-06-12 Thread Peter
Re: What's wrong with this approach db.payment_allocations.insert(**{'payment_ref': payment.id, ref_field: record.id, 'amount_allocated': allocation}) To be honest I was trying to up my game with a bit of abstraction but haven't u

[web2py] Re: Trying to use a variable as a field name in a table insert

2017-06-09 Thread Anthony
What's wrong with this approach: https://groups.google.com/d/msg/web2py/_VsOlcA2qFk/6whMJl8tAwAJ On Friday, June 9, 2017 at 12:03:00 AM UTC-4, Peter wrote: > > > I see... >> >> TypeError: some_function() got an unexpected keyword argument >> 'parameter_name' >> > > > I was trying to avoid the

[web2py] Re: Trying to use a variable as a field name in a table insert

2017-06-08 Thread Peter
I see... > > TypeError: some_function() got an unexpected keyword argument > 'parameter_name' > I was trying to avoid the if else but if it's the better way, so be it and I have changed the code using a session cookie... if session.allocations_table_name == 'task': db.payment_allocations

[web2py] Re: Trying to use a variable as a field name in a table insert

2017-06-08 Thread Anthony
This is not valid: def some_function(the_real_parameter): print the_real_parameter parameter_name = 'the_real_parameter' some_function(parameter_name='hello') Anthony On Thursday, June 8, 2017 at 2:49:17 PM UTC-4, Peter wrote: > > > Thanks for that Anthony! (I have a feeling of deja vu a

[web2py] Re: Trying to use a variable as a field name in a table insert

2017-06-08 Thread Peter
Thanks for that Anthony! (I have a feeling of deja vu about that one) If you have time can you tell me what you mean... That's not valid Python code I'm not sure what it refers to and would like understand where I am doing something wrong. Regards Peter -- Resources: - http://web2py.com

[web2py] Re: Trying to use a variable as a field name in a table insert

2017-06-07 Thread Anthony
That's not valid Python code, but you can do this: db.payment_allocations.insert(**{'payment_ref': payment.id, ref_field: record.id, 'amount_allocated': allocation}) Anthony On Wednesday, June 7, 2017 at 10:42:28 PM UTC-4, Peter w