Message from discussion
How to print a number as if in the python interpreter?
Received: by 10.68.190.104 with SMTP id gp8mr14533551pbc.4.1341614318639;
Fri, 06 Jul 2012 15:38:38 -0700 (PDT)
Path: l9ni11017pbj.0!nntp.google.com!news2.google.com!postnews.google.com!j25g2000yqn.googlegroups.com!not-for-mail
From: Peng Yu <pengyu...@gmail.com>
Newsgroups: comp.lang.python
Subject: How to print a number as if in the python interpreter?
Date: Fri, 6 Jul 2012 15:38:38 -0700 (PDT)
Organization: http://groups.google.com
Lines: 16
Message-ID: <10e16ff7-b5cf-4c77-8b7d-f58c035f748a@j25g2000yqn.googlegroups.com>
NNTP-Posting-Host: 128.249.1.202
Mime-Version: 1.0
X-Trace: posting.google.com 1341614318 1017 127.0.0.1 (6 Jul 2012 22:38:38 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Fri, 6 Jul 2012 22:38:38 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: j25g2000yqn.googlegroups.com; posting-host=128.249.1.202; posting-account=QQ-KfAoAAABDVwrVNFoaFFcBU7ec1cHk
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:13.0)
Gecko/20100101 Firefox/13.0.1,gzip(gfe)
Content-Type: text/plain; charset=ISO-8859-1
Hi,
In [2]: sum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1])
Out[2]: 0.9999999999999999
In ipython, I got the above output. But I got a different output from
"print". Is there a way to print exact what I saw in ipython?
~/linux/test/python/man/library/math/fsum$ cat main.py
#!/usr/bin/env python
print sum([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1])
~/linux/test/python/man/library/math/fsum$ ./main.py
1.0
Regards,
Peng