Re: repr/str diff between Python 2 and 3

2016-10-12 Thread Skip Montanaro
Thanks everyone. I'm not going to try to be too cute, and will just change my test case. I'm leaving Python 2 behind in this particular case for now anyway. I can always return to the issue if I decide I need Python 2.7 support at some point in the future. Skip -- https://mail.python.org/mailman/

Re: repr/str diff between Python 2 and 3

2016-10-11 Thread Serhiy Storchaka
On 12.10.16 04:30, Skip Montanaro wrote: https://docs.python.org/3/whatsnew/3.1.html It's the third hit when searching for 'float'. Assuming I understand what it's saying. ;) Thanks. Is that the "David Gay's algorithm"? That seems to apply only to repr(), while the change I observed was in

Re: repr/str diff between Python 2 and 3

2016-10-11 Thread Terry Reedy
On 10/11/2016 9:30 PM, Skip Montanaro wrote: https://docs.python.org/3/whatsnew/3.1.html It's the third hit when searching for 'float'. Assuming I understand what it's saying. ;) Thanks. Is that the "David Gay's algorithm"? That seems to apply only to repr(), while the change I observed was

Re: repr/str diff between Python 2 and 3

2016-10-11 Thread Ethan Furman
On 10/11/2016 06:30 PM, Skip Montanaro wrote: https://docs.python.org/3/whatsnew/3.1.html It's the third hit when searching for 'float'. Assuming I understand what it's saying. ;) Thanks. Is that the "David Gay's algorithm"? That seems to apply only to repr(), while the change I observed wa

Re: repr/str diff between Python 2 and 3

2016-10-11 Thread Ben Finney
Skip Montanaro writes: > > Only that one should not rely on ‘str’ preserving the value accurately, > > as documented in Python 2. > > Sure, but this choice is out of my hands. It's csv.writerow that calls > str(), not me. Ah, good old ‘csv’. If the implementation is leaking an abstraction and y

Re: repr/str diff between Python 2 and 3

2016-10-11 Thread Terry Reedy
On 10/11/2016 8:59 PM, Skip Montanaro wrote: I'm trying to port some code from Python 2 to 3, and beyond the usual mechanical stuff, I've encountered a difference between the str() of floats. Here's an example. In Python 3 I get: print(repr(27.04 - 0.01)) 27.028 print(str(27.04 -

Re: repr/str diff between Python 2 and 3

2016-10-11 Thread Skip Montanaro
> Only that one should not rely on ‘str’ preserving the value accurately, > as documented in Python 2. Sure, but this choice is out of my hands. It's csv.writerow that calls str(), not me. I could probably subclass csv.writer and csv.DictWriter, and override the writerow method, but I would prefer

Re: repr/str diff between Python 2 and 3

2016-10-11 Thread Skip Montanaro
> https://docs.python.org/3/whatsnew/3.1.html > > It's the third hit when searching for 'float'. Assuming I understand what it's saying. ;) Thanks. Is that the "David Gay's algorithm"? That seems to apply only to repr(), while the change I observed was in str(). Skip -- https://mail.python.or

Re: repr/str diff between Python 2 and 3

2016-10-11 Thread Ben Finney
Skip Montanaro writes: > >>> print repr(27.04 - 0.01) > 27.028 > >>> print str(27.04 - 0.01) > 27.03 > > My test case writes through a csv writer, which writes the str() of each > element to the output. For Python 2, that's a mistake: str(object='') Return a string containi

Re: repr/str diff between Python 2 and 3

2016-10-11 Thread Ethan Furman
On 10/11/2016 05:59 PM, Skip Montanaro wrote: Is there documentation of this particular change? My searching turned up documentation of plenty of other changes, but not this particular one. 3.1 What's new: https://docs.python.org/3/whatsnew/3.1.html It's the third hit when searching for 'f