Parsing a large number of parms to a print statement.

Discussion in 'Python' started by KB, Oct 22, 2009.

  1. KB

    KB Guest

    Hi,

    I have to pass over 150 parameters to a print statement ala:

    print "%s <text> %s <other text> %s ....<150'th unique text> %s" % (v
    [0], v[1], ... v[150])

    I can't use a for loop like I normally would over the list "v" due to
    the different text fragments between each var.

    Is there a lambda function I can use in place of '% (v[0],v[1]...v
    [150])' ???

    Thanks in advance.
    KB, Oct 22, 2009
    #1
    1. Advertising

  2. KB

    Ethan Furman Guest

    KB wrote:
    > Hi,
    >
    > I have to pass over 150 parameters to a print statement ala:
    >
    > print "%s <text> %s <other text> %s ....<150'th unique text> %s" % (v
    > [0], v[1], ... v[150])
    >
    > I can't use a for loop like I normally would over the list "v" due to
    > the different text fragments between each var.
    >
    > Is there a lambda function I can use in place of '% (v[0],v[1]...v
    > [150])' ???
    >
    > Thanks in advance.


    Actually, you are only sending one parameter to print.

    Is v iterable? _And_ does v have 150 values? _And_ can you say
    tuple(v) and get (v[0], v[1], v[2], ..., v[149])? If so, try:

    print "%s blah %s blah blah %s .... " % tuple(v)

    ~Ethan~
    Ethan Furman, Oct 22, 2009
    #2
    1. Advertising

  3. KB

    Paul Rubin Guest

    KB <> writes:
    > I have to pass over 150 parameters to a print statement ala:
    >
    > print "%s <text> %s <other text> %s ....<150'th unique text> %s" % (v
    > [0], v[1], ... v[150])
    >
    > I can't use a for loop like I normally would over the list "v" due to
    > the different text fragments between each var.


    print "%s <text> ..." % tuple(v[:150])

    But what you're trying to do looks bizarre. Find a way to make the
    constant strings inside the print statement part of the data.
    Paul Rubin, Oct 22, 2009
    #3
  4. On Thu, Oct 22, 2009 at 5:16 PM, KB <> wrote:
    > Hi,
    >
    > I have to pass over 150 parameters to a print statement ala:
    >
    > print "%s <text> %s <other text> %s ....<150'th unique text> %s" % (v
    > [0], v[1], ... v[150])
    >
    > I can't use a for loop like I normally would over the list "v" due to
    > the different text fragments between each var.
    >
    > Is there a lambda function I can use in place of '% (v[0],v[1]...v
    > [150])' ???
    >
    > Thanks in advance.


    Why use a lambda?

    "<long string with lots of params>" % tuple(v)



    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
    Benjamin Kaplan, Oct 22, 2009
    #4
  5. KB

    MRAB Guest

    KB wrote:
    > Hi,
    >
    > I have to pass over 150 parameters to a print statement ala:
    >
    > print "%s <text> %s <other text> %s ....<150'th unique text> %s" % (v
    > [0], v[1], ... v[150])
    >
    > I can't use a for loop like I normally would over the list "v" due to
    > the different text fragments between each var.
    >
    > Is there a lambda function I can use in place of '% (v[0],v[1]...v
    > [150])' ???
    >

    print "%s <text> %s <other text> %s ....<150'th unique text> %s" % tuple(v)

    If v is already a tuple then that's not necessary! :)
    MRAB, Oct 22, 2009
    #5
  6. KB

    Andre Engels Guest

    On Thu, Oct 22, 2009 at 11:16 PM, KB <> wrote:
    > Hi,
    >
    > I have to pass over 150 parameters to a print statement ala:
    >
    > print "%s <text> %s <other text> %s ....<150'th unique text> %s" % (v
    > [0], v[1], ... v[150])
    >
    > I can't use a for loop like I normally would over the list "v" due to
    > the different text fragments between each var.
    >
    > Is there a lambda function I can use in place of '% (v[0],v[1]...v
    > [150])' ???


    It's not a lambda function, but what about

    print "%s <text> %s <other text> %s ....<150'th unique text> %s" % tuple(v)




    --
    André Engels,
    Andre Engels, Oct 22, 2009
    #6
  7. KB

    KB Guest

    Excuse the top-post, but thanks to all, the tuple was the way to go.

    On Oct 22, 2:16 pm, KB <> wrote:
    > Hi,
    >
    > I have to pass over 150 parameters to a print statement ala:
    >
    > print "%s <text> %s <other text> %s ....<150'th unique text> %s" % (v
    > [0], v[1], ... v[150])
    >
    > I can't use a for loop like I normally would over the list "v" due to
    > the different text fragments between each var.
    >
    > Is there a lambda function I can use in place of '% (v[0],v[1]...v
    > [150])' ???
    >
    > Thanks in advance.
    KB, Oct 22, 2009
    #7
    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. Tim Jones
    Replies:
    0
    Views:
    718
    Tim Jones
    Dec 17, 2003
  2. Tim Jones
    Replies:
    1
    Views:
    1,984
    Jerry Boone
    Dec 18, 2003
  3. Jeff Jarrell
    Replies:
    0
    Views:
    544
    Jeff Jarrell
    Oct 26, 2005
  4. Tim Jowers

    obj,fn,parms encapsulation in java

    Tim Jowers, Sep 13, 2004, in forum: Java
    Replies:
    1
    Views:
    375
    Alan Meyer
    Sep 13, 2004
  5. cenbka

    ObjectDataSource.SelectMethod with variable number of parms

    cenbka, Dec 8, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    244
    cenbka
    Dec 8, 2005
Loading...

Share This Page