Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #89539
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!feeds.phibee-telecom.net!news.panservice.it!feed.xsnews.nl!border02.ams.xsnews.nl!feeder04.ams.xsnews.nl!abp002.ams.xsnews.nl!frontend-F09-18.ams.news.kpn.nl |
|---|---|
| From | Cecil Westerhof <Cecil@decebal.nl> |
| Newsgroups | comp.lang.python |
| Subject | str more precise in 3 as 2.7 |
| Organization | Decebal Computing |
| X-Face | "(y8cC@tg_12{">GF'UXTW]FHI2wMiZNrnf'1EFQ&O#$m:f#O7+7}kR<J%a^F2lh4[N~Yz4 nSp#c+aQo1b5=?HcNEkQ7QzF<])O3X4MDL/AYjys&*mt>,v+Pti8=Vi/Z"g^?b"E |
| X-Homepage | http://www.decebal.nl/ |
| Date | Wed, 29 Apr 2015 13:24:57 +0200 |
| Message-ID | <87twvzch2u.fsf@Equus.decebal.nl> (permalink) |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
| Cancel-Lock | sha1:n+KGM4Q+fL92fJHDssYJc9qBw8A= |
| MIME-Version | 1.0 |
| Content-Type | text/plain |
| Lines | 26 |
| NNTP-Posting-Host | 81.207.62.244 |
| X-Trace | 1430306929 news.kpn.nl 18083 81.207.62.244@kpn/81.207.62.244:42316 |
| Xref | csiph.com comp.lang.python:89539 |
Show key headers only | View raw
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'
Earlier I did:
import sys
# For when the difference between 2 and 3 is important
python_version = sys.version_info[0]
At the moment I use it only once, but it is never bad to be prepared.
--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
str more precise in 3 as 2.7 Cecil Westerhof <Cecil@decebal.nl> - 2015-04-29 13:24 +0200
Re: str more precise in 3 as 2.7 Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-04-29 12:50 +0100
Re: str more precise in 3 as 2.7 Chris Angelico <rosuav@gmail.com> - 2015-04-29 21:55 +1000
Re: str more precise in 3 as 2.7 Cecil Westerhof <Cecil@decebal.nl> - 2015-04-29 14:09 +0200
Re: str more precise in 3 as 2.7 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-04-30 14:29 +1000
csiph-web