Re: Question about ast.literal_eval

Discussion in 'Python' started by Frank Millman, May 20, 2013.

  1. [Corrected top-posting]

    >> To:
    >> From:
    >> Subject: Question about ast.literal_eval
    >> Date: Mon, 20 May 2013 09:05:48 +0200
    >>
    >> Hi all
    >>
    >> I am trying to emulate a SQL check constraint in Python. Quoting from
    >> the PostgreSQL docs, "A check constraint is the most generic constraint
    >> type. It allows you to specify that the value in a certain column must
    >> satisfy a Boolean (truth-value) expression."
    >>
    >> The problem is that I want to store the constraint as a string, and I
    >> was hoping to use ast.literal_eval to evaluate it, but it does not work.
    >>


    On 20/05/2013 09:34, Carlos Nepomuceno wrote:

    > It seems to me you can't use ast.literal_eval()[1] to evaluate that kind of expression
    > because it's just for literals[2].
    >
    > Why don't you use eval()?
    >


    Because users can create their own columns, with their own constraints.
    Therefore the string is user-modifiable, so it cannot be trusted.

    Frank
     
    Frank Millman, May 20, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Frank Millman

    Question about ast.literal_eval

    Frank Millman, May 20, 2013, in forum: Python
    Replies:
    2
    Views:
    158
    Frank Millman
    May 21, 2013
  2. Carlos Nepomuceno

    RE: Question about ast.literal_eval

    Carlos Nepomuceno, May 20, 2013, in forum: Python
    Replies:
    0
    Views:
    98
    Carlos Nepomuceno
    May 20, 2013
  3. Chris Angelico

    Re: Question about ast.literal_eval

    Chris Angelico, May 20, 2013, in forum: Python
    Replies:
    0
    Views:
    108
    Chris Angelico
    May 20, 2013
  4. Chris Angelico

    Re: Question about ast.literal_eval

    Chris Angelico, May 20, 2013, in forum: Python
    Replies:
    0
    Views:
    95
    Chris Angelico
    May 20, 2013
  5. Carlos Nepomuceno

    RE: Question about ast.literal_eval

    Carlos Nepomuceno, May 20, 2013, in forum: Python
    Replies:
    1
    Views:
    121
    Steven D'Aprano
    May 20, 2013
Loading...

Share This Page