On Wednesday 11 April 2007 14:53, Johnny Blonde wrote:
> Hello Group,
>
> from a form i receive a list like this
>
> param = "(34477,36),(34477,8),(34477,9),(39290,36),(39290,8),
> (39290,9),"
>
> this is the result of a number of checkboxes, all named "param" and
> with values like "(34477,36),"
> example:
> <input type="checkbox" value="(34477,36)," name="sales"/>
> <input type="checkbox" value="(34477,8)," name="sales"/>
>
>
> when i do
>
> s= eval(param)
> on the shell
>
> s is a list of tuples, which is just what i want.
>
> >>> s = eval (param)
> >>> s
>
> ((34477, 36), (34477, 8), (34477, 9), (39290, 36), (39290, 8), (39290,
> 9))
>
> >>> s[0]
>
> (34477, 36)
>
> >>> s[0][0]
>
> 34477
>
>
> when i do the same thing in my tg controller, s is a list, too, but
> printing out:
> s[0][0] returns "(" instead of 34477
>
> what´s the best way to receive the tuples within turbogears just like
> i get them in the shell?
The best way is not to do it. Because eval is evil. If someone puts a
'import shutil;shutil.rmtree("/")'
in your http-request, you'll be in trouble.
Instead, I would encode the tuples like this:
"%i_%i" % tuple_value
when rendering, and later when retrieving them, do a simple
tuple_value = tuple(int(v) for v in request.param[0].split('_'))
Another approach would be to utilize a validator with it's respectiv
_from_python and _to_python methods.
Diez
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---