Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Parsing a large number of parms to a print statement.

Reply
Thread Tools

Parsing a large number of parms to a print statement.

 
 
KB
Guest
Posts: n/a
 
      10-22-2009
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.
 
Reply With Quote
 
 
 
 
Ethan Furman
Guest
Posts: n/a
 
      10-22-2009
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~
 
Reply With Quote
 
 
 
 
Paul Rubin
Guest
Posts: n/a
 
      10-22-2009
KB <(E-Mail Removed)> 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.
 
Reply With Quote
 
Benjamin Kaplan
Guest
Posts: n/a
 
      10-22-2009
On Thu, Oct 22, 2009 at 5:16 PM, KB <(E-Mail Removed)> 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
>

 
Reply With Quote
 
MRAB
Guest
Posts: n/a
 
      10-22-2009
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!

 
Reply With Quote
 
Andre Engels
Guest
Posts: n/a
 
      10-22-2009
On Thu, Oct 22, 2009 at 11:16 PM, KB <(E-Mail Removed)> 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, http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
KB
Guest
Posts: n/a
 
      10-22-2009
Excuse the top-post, but thanks to all, the tuple was the way to go.

On Oct 22, 2:16*pm, KB <(E-Mail Removed)> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ObjectDataSource.SelectMethod with variable number of parms cenbka ASP .Net Datagrid Control 0 12-08-2005 09:54 PM
anchor tag - how to initiate postback with parms Jeff Jarrell ASP .Net 0 10-26-2005 02:32 AM
obj,fn,parms encapsulation in java Tim Jowers Java 1 09-13-2004 10:39 PM
Crytal Reports...Export Error with parms Tim Jones ASP .Net 1 12-18-2003 07:52 PM
Crystal Reports - with parms - .Export error Tim Jones ASP .Net 0 12-17-2003 05:54 PM



Advertisments