Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Feature request: New string conversion type to ignore list item

1 view
Skip to first unread message

thoma...@gmail.com

unread,
Jun 5, 2007, 6:53:56 AM6/5/07
to
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

Peter Otten

unread,
Jun 5, 2007, 7:12:01 AM6/5/07
to
thoma...@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

thoma...@gmail.com

unread,
Jun 5, 2007, 7:27:43 AM6/5/07
to
On 5 Jun., 13:12, Peter Otten <__pete...@web.de> wrote:

> or like this:
>
> >>> "%s %.s %s" % ("first", "second", "third")
>
> 'first third'

Hey, that's great, thanks Peter!

Tom

pelon

unread,
Jun 11, 2007, 9:11:12 PM6/11/07
to

Why not be consistent with other aspects of the language:

"%s %!s %s" % ("first", "second", "third")


Message has been deleted

Steven Bethard

unread,
Jun 12, 2007, 12:03:22 AM6/12/07
to pelon

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

0 new messages