Re: [f2py] f2py AttributeError

"Gabor Kalman" <[email protected]> Sat, 02 Mar 2013 13:59:29 -0800
Newsgroups gmane.comp.python.f2py.user
Message-ID <767A448C252849589FB530DFFE1CDFD6@ToshibaGPC>
This is a multi-part message in MIME format.

--===============8131141715619799989==
Content-type: multipart/alternative;
 boundary="----=_NextPart_000_0008_01CE174E.28661630"

This is a multi-part message in MIME format.

------=_NextPart_000_0008_01CE174E.28661630
Content-Type: text/plain;
	charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable

Thanks so much. I somehow must have missed the significance of the =93 =
.__doc__=94  documentations. This issue  is now COMPLETELY clear to me.

From: Pearu Peterson=20
Sent: Saturday, March 02, 2013 12:45 PM
To: For users of the f2py program=20
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 <[email protected]> =
wrote:

  I hope that  I can save someone=92s 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=3Dlib1.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=3Dlib1.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//[email protected]
  http://cens.ioc.ee/mailman/listinfo/f2py-users





-------------------------------------------------------------------------=
-------
_______________________________________________
f2py-users mailing list
f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]
http://cens.ioc.ee/mailman/listinfo/f2py-users

------=_NextPart_000_0008_01CE174E.28661630
Content-Type: text/html;
	charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable

<HTML><HEAD></HEAD>
<BODY dir=3Dltr>
<DIV dir=3Dltr>
<DIV style=3D"FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: 12pt">
<DIV>Thanks so much. I somehow must have missed the significance of the =
=93=20
.__doc__=94&nbsp; documentations. This issue&nbsp; is now COMPLETELY =
clear to=20
me.</DIV>
<DIV=20
style=3D"FONT-STYLE: normal; DISPLAY: inline; FONT-FAMILY: 'Calibri'; =
COLOR: #000000; FONT-SIZE: small; FONT-WEIGHT: normal; TEXT-DECORATION: =
none">
<DIV style=3D"FONT: 10pt tahoma">
<DIV>&nbsp;</DIV>
<DIV style=3D"BACKGROUND: #f5f5f5">
<DIV style=3D"font-color: black"><B>From:</B> <A [email protected]=20
href=3D"mailto:[email protected]">Pearu Peterson</A> </DIV>
<DIV><B>Sent:</B> Saturday, March 02, 2013 12:45 PM</DIV>
<DIV><B>To:</B> <A title=3Df2py-users-Y4l6ocDipWCuvFJfX82//[email protected]=20
href=3D"mailto:f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]">For users of the f2py program</A> =
</DIV>
<DIV><B>Subject:</B> Re: [f2py] f2py AttributeError</DIV></DIV></DIV>
<DIV>&nbsp;</DIV></DIV>
<DIV=20
style=3D"FONT-STYLE: normal; DISPLAY: inline; FONT-FAMILY: 'Calibri'; =
COLOR: #000000; FONT-SIZE: small; FONT-WEIGHT: normal; TEXT-DECORATION: =
none">
<DIV dir=3Dltr>
<DIV>
<DIV>Hi,<BR><BR></DIV>While Python is case-sensitive, Fortran is =
not.<BR></DIV>
<DIV><BR>In Fortran, foo, Foo, FOO, fOo, etc are all the same while at =
the=20
object code level they are all referred with unique (in general, =
compiler=20
dependent) name: foo_<BR></DIV>
<DIV>By default, f2py also mangles the Fortran names by lowering the =
cases and=20
that is why RK4 appears as rk4 in the wrapper module.<BR><BR></DIV>
<DIV>To avoid this kind of surprises (there could be more, for instance, =
Fortran=20
intent(out) arguments are return values in the corresponding Python =
wrapper=20
functions), it is always recommended to print out the documentation =
strings of=20
wrapper modules and functions. For instance, see<BR><BR></DIV>
<DIV>print lib1.__doc__<BR></DIV>
<DIV>print lin1.aa.__doc__<BR></DIV>
<DIV>&nbsp;</DIV>
<DIV>This is all explained in f2py docs.<BR></DIV>
<DIV>&nbsp;</DIV>
<DIV>Best regards,<BR></DIV>Pearu<BR></DIV>
<DIV class=3Dgmail_extra><BR><BR>
<DIV class=3Dgmail_quote>On Sat, Mar 2, 2013 at 9:55 PM, Gabor Kalman =
<SPAN=20
dir=3Dltr>&lt;<A href=3D"mailto:[email protected]"=20
target=3D_blank>[email protected]</A>&gt;</SPAN> wrote:<BR>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; =
PADDING-LEFT: 1ex"=20
class=3Dgmail_quote>
  <DIV dir=3Dltr>
  <DIV dir=3Dltr>
  <DIV style=3D"FONT-FAMILY: 'Calibri'; FONT-SIZE: 12pt">
  <DIV><FONT size=3D5><STRONG>I hope that&nbsp; I can save someone=92s =
time with the=20
  following message:</STRONG></FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV>I wrote a small script in gfortran:</DIV>
  <DIV>!-----------------------</DIV>
  <DIV>file: <STRONG>RK4-test.f90</STRONG></DIV>
  <DIV>&nbsp;</DIV>
  <DIV>module aa</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>subroutine RK4(args)&nbsp;&nbsp; !!!please note RK4 is in all =
CAPS</DIV>
  <DIV>...</DIV>
  <DIV>end subroutine RK4</DIV>
  <DIV>....</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>end module aa</DIV>
  <DIV>!------------------------------------</DIV>
  <DIV>then compiled it into <STRONG>lib1.pyd</STRONG></DIV>
  <DIV>&nbsp;</DIV>
  <DIV>then with the f2py&nbsp; driver:</DIV>
  <DIV>#------------------------------</DIV>
  <DIV><STRONG>test.py</STRONG></DIV>
  <DIV>&nbsp;</DIV>
  <DIV>import lib1</DIV>
  <DIV>s=3Dlib1.aa.RK4(args)</DIV>
  <DIV>print s</DIV>
  <DIV>#------------------------------</DIV>
  <DIV>I got an obscure message:&nbsp;&nbsp; <STRONG>AttributeError in=20
  RK4</STRONG></DIV>
  <DIV><STRONG></STRONG>&nbsp;</DIV>
  <DIV>After a lot of searches I was ready to give up,</DIV>
  <DIV>but then I ACCIDENTLY Ire-wrote the driver as:</DIV>
  <DIV>#-------------------------------------------</DIV>
  <DIV><STRONG>test.py</STRONG></DIV>
  <DIV>&nbsp;</DIV>
  <DIV>import lib1</DIV>
  <DIV>s=3Dlib1.aa.rk4(args)&nbsp; !!!please note rk4 in =
LOWER-CASE</DIV>
  <DIV>print s</DIV>
  <DIV>#----------------------------------------</DIV>
  <DIV>and&nbsp; SUDDENLY everything worked OK!!!!</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>Yes, while I know Python is<STRONG> case-sensitive</STRONG>, but =
this=20
  still surprised me.</DIV>
  <DIV>&nbsp;</DIV>
  <DIV>&nbsp;</DIV>
  =
<DIV>&nbsp;</DIV></DIV></DIV></DIV><BR>__________________________________=
_____________<BR>f2py-users=20
  mailing list<BR><A=20
  =
href=3D"mailto:f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]">f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]</A><BR><A=20
  href=3D"http://cens.ioc.ee/mailman/listinfo/f2py-users"=20
  =
target=3D_blank>http://cens.ioc.ee/mailman/listinfo/f2py-users</A><BR><BR=
></BLOCKQUOTE></DIV>
<DIV>&nbsp;</DIV></DIV>
<P>
<HR>
_______________________________________________<BR>f2py-users mailing=20
list<BR>f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]<BR>http://cens.ioc.ee/mailman/listinfo/f2p=
y-users<BR></DIV></DIV></DIV></BODY></HTML>

------=_NextPart_000_0008_01CE174E.28661630--



--===============8131141715619799989==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
f2py-users mailing list
f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]
http://cens.ioc.ee/mailman/listinfo/f2py-users

--===============8131141715619799989==--