简体   繁体   English

如何在python中使用f2py模块

[英]How to Use f2py module in python

Just having a bit of trouble with using f2py. 使用f2py有点麻烦。 I have compiled to following code into a .so file just fine, and it imports into my python code just fine, but I am just wondering how do I then use it. 我已经将下面的代码编译到.so文件中,并且可以将其导入到我的python代码中,但是我只是想知道如何使用它。 I know there is a command doc but it jus says that this module has no attribute called " doc " 我知道有一个命令doc,但是它说该模块没有名为“ doc ”的属性

Fortran Code: Fortran代码:

subroutine Test
implicit none
real, dimension(3600000) :: Alpha,Sigma
open(10, file='Alpha.txt')
read(10, *) Alpha
Sigma = (87.6*2)/((87.6*(sin(Alpha))**2)+(2*cos(Alpha)**2))
end subroutine

Python Code: Python代码:

import matplotlib.pyplot as plt 
import numpy as np 
import Sigma

print(Sigma._doc_)

Error: 错误:

File "/home/tom/Desktop/f2py/Plot.py", line 5, in <module>
    print(Sigma._doc_)
AttributeError: 'module' object has no attribute '_doc_'

Do I have to somehow enter the doc attribute into the original fortran code? 我是否必须以某种方式将doc属性输入到原始的fortran代码中? If so how would I go about that? 如果是这样,我将如何处理?

According to their example , it looks like you need to call the print on module.subroutine.__doc__ . 根据他们的示例 ,您似乎需要在module.subroutine.__doc__上调用打印。

If I save your file to test1.f90 , then compile it 如果我将文件保存到test1.f90 ,则进行编译

f2py -c test1.f90 -m test1

And then query the doc string. 然后查询文档字符串。

~$ python
Python 3.6.4 (default, Jan  5 2018, 02:35:40) 
[GCC 7.2.1 20171224] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> import test1
>>> print(test1.test.__doc__)
test()

Wrapper for ``test``.


>>>

Which looks fine to me since you have no arguments going to Test . 对我来说,这很好,因为您没有要Test参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM