On Thursday 23 June 2005 13:50, phi...@ho... wrote:
> Hi list,
> My question is pure pythonic but is linked to pytables.
>
> I allows user to select data from an array by letting him type the
> expression of the comprehension list.
>
> For example,
>
> x[?pressure?] for x in table.iterrows() if x[?TDCcount?]>3 and
> 20<=x[?pressure?]<50.
>
> I wanted to create a python list comprehension from the previsou string.
>
> Is is possible?
Yes: eval("[%s]" % userstring)
However, this practice is not recommended because the user may
introduce malign code (which can be dangerous if, for example, you are
developing an app on a public web).
> Is there another solution?
Yes. Parse the info that wants the user, pass it to a function, and
return the list of results. This represents much more work, though, so
you may want to stick with the previous solution to start with.
Cheers,
--
Francesc
|