Constructing an if statement from the client data in python

Chris Rebert clp2 at rebertia.com
Tue Apr 13 15:29:14 EDT 2010


On Tue, Apr 13, 2010 at 8:56 AM, Vishal Rana <ranavishal at gmail.com> wrote:
> Hi,
>
> I need to construct an if statement from the data coming from the client as
> below:
>
> conditions: condition1, condition2, condition3, condition4 logical
> operators: lo1, lo2, lo3 (Possible values: "and" "or")
>
> Eg.
>
> if condition1 lo1 condition2 lo3 condition4:
>
>     # Do something
>
> I can think of eval/exec but not sure how safe they are! Any better approach
> or alternative? Appreciate your responses :)
>
> PS: Client-side: Flex, Server-side: Python, over internet

Do you literally get a string, or do/could you get the expression in a
more structured format?

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list