One simple solution could be to grep (or re.compile) something like "import (.*)|from (.*) import .*" but what for import statement like:
fromor multiple import on one line?
So, if I had to rewrite the Python interpreter parser, why not use that exact parser?
I started with the parser module, but its output is not so parsable :) even if you can recall the structure (i.e. import statements are at nodes with id = 282, with imported module at id = 287 and so on). It's really powerful, but too low level for this task.
But there is another interesting module: compiler (it's deprecated in 2.6 and removed in 3.0, but I'm working with 2.5, so it's fine). Using parseFile and some objects from compiler.ast, I wrote a simple script that parses a file given in input and prints out the modules imported with "import mod" or with "from mod import xxx".
Suggestions are always welcome :)
UPDATE: please note that conditional imports are included in the list and the calls to __import__ are ignored.