Re: help

Discussion in 'Python' started by Tim Chase, Jul 20, 2012.

  1. Tim Chase

    Tim Chase Guest

    On 07/19/12 19:32, Miriam Gomez Rios wrote:
    >>>> s = "('per1','persona1.1','pro1'),('per1','persona1.1','pro2')"

    >> resulting_tuple_of_tuples = ast.literal_eval(s)

    >
    > Traceback (most recent call last):
    > File "C:\Users\Miriam\scripts\prueba_datos", line 124, in <module>
    > print resulting_tuple.select('perf1','*','*')
    > AttributeError: 'tuple' object has no attribute 'select'


    [copying the list, trimming your reply and changing to inline
    quoting for easier reading]

    I'm not sure why you expect there to be a .select method on the
    resulting object. Neither a list-of-tuples or a tuple-of-tuples has
    a .select method. It *sounds* like what you want to do is then to
    do something like

    d = ast.literal_eval(s) # data as a tuple-of-tuples
    filtered = [t for t in d where t[0] == "perf1"]

    or you can do

    filtered = [(v1,v2,v3) for (v1,v2,v3) in d where v1=="perf1"]

    which allows you to assign more meaningful names to the bits, as
    well as rearrange/select the contents:

    filtered = [(v3,v2) for (v1,v2,v3) in d where v1=="perf1"]

    or you can even do further work like instantiating objects:

    filtered = [MyCls(v3,v2) for (v1,v2,v3) in d where v1=="perf1"]

    Espero q' eso le ayuda a usted.

    -tkc
    Tim Chase, Jul 20, 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. =?Utf-8?B?dHJlbGxvdzQyMg==?=

    HELP! HELP! HELP! Opening Web Application Project Error

    =?Utf-8?B?dHJlbGxvdzQyMg==?=, Feb 20, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    742
    =?Utf-8?B?dHJlbGxvdzQyMg==?=
    Feb 20, 2004
  2. Harvey
    Replies:
    0
    Views:
    669
    Harvey
    Jul 16, 2004
  3. Harvey
    Replies:
    1
    Views:
    818
    Daniel
    Jul 16, 2004
  4. =?Utf-8?B?S2ltb24gSWZhbnRpZGlz?=

    HELP - HELP - HELP

    =?Utf-8?B?S2ltb24gSWZhbnRpZGlz?=, Mar 9, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    663
    Eliyahu Goldin
    Mar 9, 2006
  5. Buster

    Help, Help, Help

    Buster, Oct 4, 2003, in forum: Java
    Replies:
    3
    Views:
    463
    Saager
    Oct 30, 2003
Loading...

Share This Page