Re: Converting a list of strings into a list of integers?

Discussion in 'Python' started by Paul Rubin, Jul 22, 2012.

  1. Paul Rubin

    Paul Rubin Guest

    Tony the Tiger <> writes:
    > # options.modus_list contains, e.g., "[2,3,4]"


    Try this:

    import ast
    MODUS_LIST = ast.literal_eval(options.modus_list)

    literal_eval is like eval except it can only evaluate literals rather
    than calling functions and the like. The idea is you can use it on
    untrusted data.
     
    Paul Rubin, Jul 22, 2012
    #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. Roy Smith
    Replies:
    1
    Views:
    167
    Peter Otten
    Jul 22, 2012
  2. Jan Riechers
    Replies:
    4
    Views:
    221
  3. David Robinow
    Replies:
    0
    Views:
    169
    David Robinow
    Jul 22, 2012
  4. Jan Riechers
    Replies:
    0
    Views:
    158
    Jan Riechers
    Jul 22, 2012
  5. Ian Kelly
    Replies:
    0
    Views:
    141
    Ian Kelly
    Jul 22, 2012
Loading...

Share This Page