Re: [Python-Dev] [Python-checkins] cpython (3.2): Avoid codec spelling issues by just using the utf-8 default.
2011/5/5 raymond.hettinger <python-checkins@python.org>:
http://hg.python.org/cpython/rev/1a56775c6e54 changeset: 69857:1a56775c6e54 branch: 3.2 parent: 69855:97a4855202b8 user: Raymond Hettinger <python@rcn.com> date: Thu May 05 11:35:50 2011 -0700 summary: Avoid codec spelling issues by just using the utf-8 default.
Out of curiosity, what is the issue?
files: Lib/random.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/Lib/random.py b/Lib/random.py --- a/Lib/random.py +++ b/Lib/random.py @@ -114,7 +114,7 @@ if version == 2: if isinstance(a, (str, bytes, bytearray)): if isinstance(a, str): - a = a.encode("utf8") + a = a.encode()
-- Regards, Benjamin
On May 5, 2011, at 11:41 AM, Benjamin Peterson wrote:
2011/5/5 raymond.hettinger <python-checkins@python.org>:
http://hg.python.org/cpython/rev/1a56775c6e54 changeset: 69857:1a56775c6e54 branch: 3.2 parent: 69855:97a4855202b8 user: Raymond Hettinger <python@rcn.com> date: Thu May 05 11:35:50 2011 -0700 summary: Avoid codec spelling issues by just using the utf-8 default.
Out of curiosity, what is the issue?
IIRC, the performance depended on how your spelled-it. I believe that is why the spelling got changed in Py3.3. Either way, the code is simpler by just using the default. Raymond
Raymond Hettinger wrote:
On May 5, 2011, at 11:41 AM, Benjamin Peterson wrote:
2011/5/5 raymond.hettinger <python-checkins@python.org>:
http://hg.python.org/cpython/rev/1a56775c6e54 changeset: 69857:1a56775c6e54 branch: 3.2 parent: 69855:97a4855202b8 user: Raymond Hettinger <python@rcn.com> date: Thu May 05 11:35:50 2011 -0700 summary: Avoid codec spelling issues by just using the utf-8 default.
Out of curiosity, what is the issue?
IIRC, the performance depended on how your spelled-it. I believe that is why the spelling got changed in Py3.3.
Not really. It got changed because we have canonical names for the codecs which the stdlib should use rather than rely on aliases. Performance-wise it only makes a difference if you use it in tight loops.
Either way, the code is simpler by just using the default.
... as long as the casual reader knows what the default it :-) I think it's better to make the choice explicit, if the code relies on a particular non-ASCII encoding. If it doesn't, than the default is fine. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, May 06 2011)
Python/Zope Consulting and Support ... http://www.egenix.com/ mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
2011-06-20: EuroPython 2011, Florence, Italy 45 days to go ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/
On Thu, May 5, 2011 at 6:32 PM, M.-A. Lemburg <mal@egenix.com> wrote: ..
Either way, the code is simpler by just using the default.
... as long as the casual reader knows what the default it :-)
.. or cares. I this particular case, it hardly matters how random bits are encoded.
Le jeudi 05 mai 2011 à 18:54 -0400, Alexander Belopolsky a écrit :
On Thu, May 5, 2011 at 6:32 PM, M.-A. Lemburg <mal@egenix.com> wrote: ..
Either way, the code is simpler by just using the default.
... as long as the casual reader knows what the default it :-)
.. or cares. I this particular case, it hardly matters how random bits are encoded.
You don't get the same random number sequence if you use a different encoding.
r=random.Random() r.seed('\xe9'.encode('iso-8859-1')); r.randint(0, 1000) 639 r.seed('\xe9'.encode('utf-8')); r.randint(0, 1000) 992
So it is useful to know how the seed was computed. The real question is which encoding gives the most random numbers? :-) Victor
On 5/5/2011 4:55 PM, Raymond Hettinger wrote:
Either way, the code is simpler by just using the default.
I thought about this and decided that the purpose of having defaults is so one does not have to always spell it out. So use it. Readers can always look it up and learn. -- Terry Jan Reedy
Le 06/05/2011 00:52, Terry Reedy a écrit :
On 5/5/2011 4:55 PM, Raymond Hettinger wrote:
Either way, the code is simpler by just using the default. I thought about this and decided that the purpose of having defaults is so one does not have to always spell it out. So use it. Readers can always look it up and learn.
Agreed. I thought about something similar after Victor’s commit that changed open(mode='rU') to use just 'r': Why not remove the mode argument entirely when it is the default value? Regards
participants (7)
-
Alexander Belopolsky -
Benjamin Peterson -
M.-A. Lemburg -
Raymond Hettinger -
Terry Reedy -
Victor Stinner -
Éric Araujo