tuple methods: documentation missing

S

Steven D'Aprano

formatting-operations>


Ah, so the rumors are true:
we are supposed to prefer
'{0:>10}'.format('wtf?')
to
'%10s' % 'wtf?'
and
'{{0}}{0}'.format('wtf?').format('wtf?') to
'%%s%s' % 'wtf?' % 'wtf?'

Well, that second example certainly is a WTF.

I think we are supposed to prefer:

'{0}{0}'.format('wtf?')
to
'%%s%s' % 'wtf?' % 'wtf?'

And frankly, I do.

According to PEP 4,
"obsolete" means "deprecated".
So the compact, simple, and useful
old string formatting is really deprecated? Ouch.

PEP 4 applies to *modules*. String formatting is not a module. Old string
formatting is obsolete but not yet deprecated. Why don't you raise the
issue on python-dev, where it may do some good?
 
A

Alan G Isaac

Well, that second example certainly is a WTF.
I think we are supposed to prefer:
'{0}{0}'.format('wtf?')
to
'%%s%s' % 'wtf?' % 'wtf?'


But your replacement misses the point of the example,
which is that sequential formatting is often needed.
That is, you need to generate a format string from
a format string. More explicitly:

'{{0}} {0}'.format('earlyinfo').format('lateinfo')

'%%s %s' % 'earlyinfo' % 'lateinfo'

But of more interest: you claim PEP 4 is not relevant,
and that old string formatting is NOT deprecated.
I would like assurance that it is not deprecated.
Can you back that?

Thanks,
Alan Isaac
 
J

John Machin

But of more interest: you claim PEP 4 is not relevant,
and that old string formatting is NOT deprecated.
I would like assurance that it is not deprecated.

It is not deprecated YET; see this:

http://docs.python.org/3.0/whatsnew/3.0.html#changes-already-present-in-python-2-6

PEP 3101: Advanced String Formatting. Note: the 2.6 description
mentions the format() method for both 8-bit and Unicode strings. In
3.0, only the str type (text strings with Unicode support) supports
this method; the bytes type does not. The plan is to eventually make
this the only API for string formatting, and to start deprecating the
% operator in Python 3.1.
 
S

Steven D'Aprano

But of more interest: you claim PEP 4 is not relevant, and that old
string formatting is NOT deprecated. I would like assurance that it is
not deprecated. Can you back that?

If you want to know what python-dev have in mind, you have to ask them,
not me.

But as I see it, the earliest % formatting could be removed would be
Python 3.2: Python 3.1 to get a formal deprecation warning, with
removal no earlier than 3.2. So you've got about a year to change their
mind about deprecating the old style, or alternatively, a year to get
used to the new style, followed by another year for % to go away
completely.
 
T

Terry Reedy

No, no 'supposed to's. You are not even 'supposed to' like or use
Python. (Unless, I supposed, an employer demands it. But that is
another story.) Certainly, one is not 'supposed to' prefer the new to
the carefully picked best use example of the old. Guido and some
developers prefer the totality of uses cases and possibilities of
..format to the same for % formatting.
But your replacement misses the point of the example,

I read it the same way and has the same thought as Steven.
Perhaps all the obviously angry 'wtf?'s distracted me.
which is that sequential formatting is often needed.
That is, you need to generate a format string from
a format string. More explicitly:

'{{0}} {0}'.format('earlyinfo').format('lateinfo')

'%%s %s' % 'earlyinfo' % 'lateinfo'

This is what you should have written. Having never seen or done this, I
first missed the doubled '%%' and read it as a syntax error.
I would like assurance that it is not deprecated.
Can you back that?

If you claim something exists, you have the burden of proof.
I have not seen 3.0 emit a % deprecation warning. Have you?

Last I read, Guido *plans* to deprecate % formatting 'sometime'.

Terry Jan Reedy
 
A

Alan G Isaac

It is not deprecated YET; see this:

http://docs.python.org/3.0/whatsnew/3.0.html#changes-already-present-in-python-2-6

PEP 3101: Advanced String Formatting. Note: the 2.6 description
mentions the format() method for both 8-bit and Unicode strings. In
3.0, only the str type (text strings with Unicode support) supports
this method; the bytes type does not. The plan is to eventually make
this the only API for string formatting, and to start deprecating the
% operator in Python 3.1.


Thanks!
Alan Isaac
 
A

Alan G Isaac

I have not seen 3.0 emit a % deprecation warning.


Point taken.

But the vocabulary of PEP 4 suggests that
"obsolete" and "deprecated" are synonyms,
and PEP 4 lists obsolete modules without
deprecation warnings.

Alan Isaac
 

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,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top