471,350 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

Feature request: New string conversion type to ignore list item

Hi,
let's assume you want to nicely print the content of a list except for
one (or some)
individual item. You could do it like this:

t = ["foo", "skip me", 1, 2, 3]
print("text: %s\nvalues: %i %i %i" % (t[0], t[2], t[3], t[4]))

If there was a conversion type which simply ignores the corresponding
list item
- let's call it "%v" like "void" - things would be much easier:

t = ["foo", "skip me", 1, 2, 3]
print("text: %s\nvalues: %v%i %i %i" % t)

I guess that this new conversion type wouldn't break any existing
code.
What do you think?

Cheers,
Tom

Jun 5 '07 #1
4 1225
th*********@gmail.com wrote:
let's assume you want to nicely print the content of a list except for
one (or some) individual item. You could do it like this:
t = ["foo", "skip me", 1, 2, 3]
print("text: %s\nvalues: %i %i %i" % (t[0], t[2], t[3], t[4]))
or like this:
>>"%s %.s %s" % ("first", "second", "third")
'first third'

Peter
Jun 5 '07 #2
On 5 Jun., 13:12, Peter Otten <__pete...@web.dewrote:
or like this:
>"%s %.s %s" % ("first", "second", "third")

'first third'
Hey, that's great, thanks Peter!

Tom

Jun 5 '07 #3
On Jun 5, 6:27 am, thomas.p...@gmail.com wrote:
On 5 Jun., 13:12, Peter Otten <__pete...@web.dewrote:
or like this:
>>"%s %.s %s" % ("first", "second", "third")
'first third'

Hey, that's great, thanks Peter!

Tom
Why not be consistent with other aspects of the language:

"%s %!s %s" % ("first", "second", "third")
Jun 12 '07 #4
pelon wrote:
On Jun 5, 6:27 am, thomas.p...@gmail.com wrote:
>On 5 Jun., 13:12, Peter Otten <__pete...@web.dewrote:
>>or like this:
>"%s %.s %s" % ("first", "second", "third")
'first third'
Hey, that's great, thanks Peter!

Tom

Why not be consistent with other aspects of the language:

"%s %!s %s" % ("first", "second", "third")
You may be interested in the Python 3000 plans, where this is written::

'{0} {2}'.format('first', 'second', 'third')

http://www.python.org/dev/peps/pep-3101/

STeVe
Jun 12 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

30 posts views Thread by Raymond Hettinger | last post: by
10 posts views Thread by Conrad Lender | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.