Parsing a large number of parms to a print statement.

K

KB

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.
 
E

Ethan Furman

KB said:
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~
 
P

Paul Rubin

KB said:
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.
 
B

Benjamin Kaplan

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)


 
M

MRAB

KB said:
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! :)
 
A

Andre Engels

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)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top