[英]python 2.7.6 f2py and ipython --pylab
使用f2py编译的fortran模块从ipython中的ascii文件读取浮点数时,发现一个奇怪的行为。 测试文件“ test.txt”仅包含一个浮点数:
5.945
我用来读取文件的子例程可以是:
subroutine read_test
implicit none
real :: dum
open(10,file='test.txt')
read(10,*) dum
print*, dum
close(10)
return
end subroutine read_test
编译与
f2py -c test.f90 -m test
如果我只是简单地使用不带命令行选项的python或ipython,则读取的数字就像文件中的数字一样。
In [1]: import test
In [2]: test.read_test()
5.94500017
使用ipython --pylab或--matplotlib给出
In [1]: import test
In [2]: test.read_test()
5.00000000
python 2.7.6,ipython 2.3.0,numpy 1.8.2和matplotlib 1.4.3会发生这种情况。 我也尝试了ipython 3.0.0、4.0.0和4.0.1,numpy 1.9.2和1.10.2以及matplotlib 1.4.3或1.5.10。 仅切换到python 2.7.10似乎可以更改预期的行为。
有人可以告诉我怎么了。 不幸的是,2.7.6是整个环境的默认设置,升级会有些麻烦。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.