On Jan 22, 10:55 am, kcrisman <kcris...@gmail.com> wrote:
> Luiz said:
>
> This worked for me, but it is definitely hackish and cumbersome. You
> basically define the function in a string, exec the string to create
> the function, and then use the function interact, instead using the
> decoration @interact. (I've read it is frowned up, but...)
> # first cell
> fields = ['a','b','c','d','e']
> init_values = [10,15,31,14,-5, 6]
> fields_def = ','.join(['%s=%d' % t for t in zip(fields,init_values)])
> fdef= 'def _(' + fields_def + '):\n' \
>     + '\tprint sum([' + ','.join(fields) + '])\n'
> print fdef   # just to check
> # second cell
> exec(fdef)
> interact(_)

I think it would be not too difficult to change @interact so that the
following worked:

fields = {'a': 10, 'b': 15, 'c': 31, 'd': 14, 'e': -5}
@interact(fields)
def _(**kwargs):
    sum = 0
    for fld_name in fields.iterkeys():
        sum += kwargs[fld_name]
    print sum

(It would be even easier if we picked a different name for this
variant of @interact.)

Would that be enough to satisfy the original requirements?  (I haven't
read the original thread, just the above message.)

Can people think of a better name for this variant of @interact?

Carl

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to