Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

f2py is a remarkable tool. And it's much easier than the documentation would lead you to believe. It's literally as simple as doing

f2py foo.f -c -m foo

Which creates a foo python module with easy access to whatever functions you put in foo.f, with proper type checking and conversion from python objects to fortran arrays. It is also clever enough to remove some unecessary inputs which are common in old fortran. For example, in fortran you usually define an extra input argument to be the length of an input array. f2py determines that this variable is uncessary as it can be determined from the length of the python object and makes it optional.

If you write fortran90-95 it's even better, as you can mark a variable as output and f2py puts it on the left side automatically.

I wish they would update it to support pointers and custom types, though. That's about the only thing it lacks right now.

It's the best and quickest way I know of linking python and native code. Scipy's weave is also nice.



Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: