[Numpy-discussion] f2py pass by reference

Pearu Peterson pearu.peterson at gmail.com
Tue Apr 12 14:45:18 EDT 2011


On Tue, Apr 12, 2011 at 9:06 PM, Mathew Yeates <mat.yeates at gmail.com> wrote:

> I have
> subroutine foo (a)
>      integer a
>      print*, "Hello from Fortran!"
>      print*, "a=",a
>      a=2
>      end
>
> and from python I want to do
> >>> a=1
> >>> foo(a)
>
> and I want a's value to now be 2.
> How do I do this?
>

With

     subroutine foo (a)
     integer a
!f2py intent(in, out) a
     print*, "Hello from Fortran!"
     print*, "a=",a
     a=2
     end

you will have desired effect:

>>> a=1
>>> a = foo(a)
>>> print a
2

HTH,
Pearu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110412/4c722234/attachment.html>


More information about the NumPy-Discussion mailing list