1

Just having a bit of trouble with using 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. I know there is a command doc but it jus says that this module has no attribute called "doc"

Fortran Code:

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:

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? If so how would I go about that?

2
  • What do you want to do with the doc? Why do you think there should be any doc present? Were you able to run the test subroutine? Commented Feb 28, 2018 at 21:19
  • You have to use the doc to find out how the functions are stored Commented Feb 28, 2018 at 22:10

1 Answer 1

1

According to their example, it looks like you need to call the print on module.subroutine.__doc__.

If I save your file to test1.f90, then compile it

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.