str more precise in 3 as 2.7

Cecil Westerhof Cecil at decebal.nl
Wed Apr 29 14:09:02 CEST 2015


Op Wednesday 29 Apr 2015 13:55 CEST schreef Chris Angelico:

> On Wed, Apr 29, 2015 at 9:24 PM, Cecil Westerhof <Cecil at decebal.nl> wrote:
>> I am trying to make my modules also work under Python 3. I found
>> that str is more precise in Python 3. The expression: str(134 /
>> 6.0) gives in 2.7.8: '22.3333333333' and in 3.4.1:
>> '22.333333333333332'
>>
>> Was not very hard to solve:
>> if python_version == 3:
>> output06[5] = '22.333333333333332'
>> output10[5] = '23.333333333333332'
>> output10[8] = '24.77777777777778'
>
> Try using repr() instead of str() - it might be more useful to you.

That looks very interesting. I am going to use it.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof



More information about the Python-list mailing list