Discussion:
[f2py] f2py AttributeError
Gabor Kalman
2013-03-02 19:55:46 UTC
Permalink
I hope that I can save someone’s time with the following message:

I wrote a small script in gfortran:
!-----------------------
file: RK4-test.f90

module aa

subroutine RK4(args) !!!please note RK4 is in all CAPS
...
end subroutine RK4
....

end module aa
!------------------------------------
then compiled it into lib1.pyd

then with the f2py driver:
#------------------------------
test.py

import lib1
s=lib1.aa.RK4(args)
print s
#------------------------------
I got an obscure message: AttributeError in RK4

After a lot of searches I was ready to give up,
but then I ACCIDENTLY Ire-wrote the driver as:
#-------------------------------------------
test.py

import lib1
s=lib1.aa.rk4(args) !!!please note rk4 in LOWER-CASE
print s
#----------------------------------------
and SUDDENLY everything worked OK!!!!

Yes, while I know Python is case-sensitive, but this still surprised me.
Pearu Peterson
2013-03-02 20:45:15 UTC
Permalink
Hi,

While Python is case-sensitive, Fortran is not.

In Fortran, foo, Foo, FOO, fOo, etc are all the same while at the object
code level they are all referred with unique (in general, compiler
dependent) name: foo_
By default, f2py also mangles the Fortran names by lowering the cases and
that is why RK4 appears as rk4 in the wrapper module.

To avoid this kind of surprises (there could be more, for instance, Fortran
intent(out) arguments are return values in the corresponding Python wrapper
functions), it is always recommended to print out the documentation strings
of wrapper modules and functions. For instance, see

print lib1.__doc__
print lin1.aa.__doc__

This is all explained in f2py docs.

Best regards,
Pearu
*I hope that I can save someone’s time with the following message:*
!-----------------------
file: *RK4-test.f90*
module aa
subroutine RK4(args) !!!please note RK4 is in all CAPS
...
end subroutine RK4
....
end module aa
!------------------------------------
then compiled it into *lib1.pyd*
#------------------------------
*test.py*
import lib1
s=lib1.aa.RK4(args)
print s
#------------------------------
I got an obscure message: *AttributeError in RK4*
**
After a lot of searches I was ready to give up,
#-------------------------------------------
*test.py*
import lib1
s=lib1.aa.rk4(args) !!!please note rk4 in LOWER-CASE
print s
#----------------------------------------
and SUDDENLY everything worked OK!!!!
Yes, while I know Python is* case-sensitive*, but this still surprised me.
_______________________________________________
f2py-users mailing list
http://cens.ioc.ee/mailman/listinfo/f2py-users
Gabor Kalman
2013-03-02 21:59:29 UTC
Permalink
Thanks so much. I somehow must have missed the significance of the “ .__doc__” documentations. This issue is now COMPLETELY clear to me.

From: Pearu Peterson
Sent: Saturday, March 02, 2013 12:45 PM
To: For users of the f2py program
Subject: Re: [f2py] f2py AttributeError

Hi,


While Python is case-sensitive, Fortran is not.


In Fortran, foo, Foo, FOO, fOo, etc are all the same while at the object code level they are all referred with unique (in general, compiler dependent) name: foo_

By default, f2py also mangles the Fortran names by lowering the cases and that is why RK4 appears as rk4 in the wrapper module.


To avoid this kind of surprises (there could be more, for instance, Fortran intent(out) arguments are return values in the corresponding Python wrapper functions), it is always recommended to print out the documentation strings of wrapper modules and functions. For instance, see


print lib1.__doc__

print lin1.aa.__doc__


This is all explained in f2py docs.


Best regards,

Pearu




On Sat, Mar 2, 2013 at 9:55 PM, Gabor Kalman <kalman_g-H+***@public.gmane.org> wrote:

I hope that I can save someone’s time with the following message:

I wrote a small script in gfortran:
!-----------------------
file: RK4-test.f90

module aa

subroutine RK4(args) !!!please note RK4 is in all CAPS
...
end subroutine RK4
....

end module aa
!------------------------------------
then compiled it into lib1.pyd

then with the f2py driver:
#------------------------------
test.py

import lib1
s=lib1.aa.RK4(args)
print s
#------------------------------
I got an obscure message: AttributeError in RK4

After a lot of searches I was ready to give up,
but then I ACCIDENTLY Ire-wrote the driver as:
#-------------------------------------------
test.py

import lib1
s=lib1.aa.rk4(args) !!!please note rk4 in LOWER-CASE
print s
#----------------------------------------
and SUDDENLY everything worked OK!!!!

Yes, while I know Python is case-sensitive, but this still surprised me.




_______________________________________________
f2py-users mailing list
f2py-users-Y4l6ocDipWCuvFJfX82//***@public.gmane.org
http://cens.ioc.ee/mailman/listinfo/f2py-users





--------------------------------------------------------------------------------
Loading...