Re: [f2py] f2py AttributeError
Pearu Peterson <[email protected]> Sat, 2 Mar 2013 22:45:15 +0200
| Newsgroups | gmane.comp.python.f2py.user |
|---|---|
| Message-ID | <CAPpwKcwTCNEKDxOiJdxV=RVU_KgO086M94=B8oSyrQHq6=RU1A@mail.gmail.com> |
--===============1274867821270136629== Content-Type: multipart/alternative; boundary=f46d0434bea670547e04d6f73341 --f46d0434bea670547e04d6f73341 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable 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 > > --f46d0434bea670547e04d6f73341 Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><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 object code level they are all referred with uniq= ue (in general, compiler dependent) name: foo_<br> </div><div>By default, f2py also mangles the Fortran names by lowering the = cases and that is why RK4 appears as rk4 in the wrapper module.<br><br></di= v><div>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 documentatio= n strings of wrapper modules and functions. For instance, see<br> <br></div><div>print lib1.__doc__<br></div><div>print lin1.aa.__doc__<br></= div><div><br></div><div>This is all explained in f2py docs.<br></div><div><= br></div><div>Best regards,<br></div>Pearu<br></div><div class=3D"gmail_ext= ra"> <br><br><div class=3D"gmail_quote">On Sat, Mar 2, 2013 at 9:55 PM, Gabor Ka= lman <span dir=3D"ltr"><<a href=3D"mailto:[email protected]" target= =3D"_blank">[email protected]</a>></span> wrote:<br><blockquote class= =3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd= ing-left:1ex"> <div dir=3D"ltr"> <div dir=3D"ltr"> <div style=3D"font-size:12pt;font-family:'Calibri'"> <div><font size=3D"5"><strong>I hope that=A0 I can save someone=92s time wi= th the=20 following message:</strong></font></div> <div>=A0</div> <div>I wrote a small script in gfortran:</div> <div>!-----------------------</div> <div>file: <strong>RK4-test.f90</strong></div> <div>=A0</div> <div>module aa</div> <div>=A0</div> <div>subroutine RK4(args)=A0=A0 !!!please note RK4 is in all CAPS</div> <div>...</div> <div>end subroutine RK4</div> <div>....</div> <div>=A0</div> <div>end module aa</div> <div>!------------------------------------</div> <div>then compiled it into <strong>lib1.pyd</strong></div> <div>=A0</div> <div>then with the f2py=A0 driver:</div> <div>#------------------------------</div> <div><strong>test.py</strong></div> <div>=A0</div> <div>import lib1</div> <div>s=3Dlib1.aa.RK4(args)</div> <div>print s</div> <div>#------------------------------</div> <div>I got an obscure message:=A0=A0 <strong>AttributeError in=20 RK4</strong></div> <div><strong></strong>=A0</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>=A0</div> <div>import lib1</div> <div>s=3Dlib1.aa.rk4(args)=A0 !!!please note rk4 in LOWER-CASE</div> <div>print s</div> <div>#----------------------------------------</div> <div>and=A0 SUDDENLY everything worked OK!!!!</div> <div>=A0</div> <div>Yes, while I know Python is<strong> case-sensitive</strong>, but this = still=20 surprised me.</div> <div>=A0</div> <div>=A0</div> <div>=A0</div></div></div></div> <br>_______________________________________________<br> f2py-users mailing list<br> <a href=3D"mailto:f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]">f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]</a><br> <a href=3D"http://cens.ioc.ee/mailman/listinfo/f2py-users" target=3D"_blank= ">http://cens.ioc.ee/mailman/listinfo/f2py-users</a><br> <br></blockquote></div><br></div> --f46d0434bea670547e04d6f73341-- --===============1274867821270136629== 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 --===============1274867821270136629==--