メモ
明後日ラボブログに書く(明日はグループ会社の親睦会)
>>> def foo(t): if isinstance(t, compiler.ast.Import): print t.names elif getattr(t, "getChildNodes"): for t in t.getChildNodes(): foo(t) >>> foo(tree) [('os', None)] >>> def what_imported(filename): tree = compiler.parse(file(filename).read()) foo(tree) >>> what_imported(r'C:\Python25\lib\os.py') [('sys', None)] [('posixpath', 'path')] [('posix', None)] [('ntpath', 'path')] [('nt', None)] [('ntpath', 'path')] [('os2emxpath', 'path')] [('os2', None)] [('macpath', 'path')] [('mac', None)] [('ntpath', 'path')] [('ce', None)] [('riscospath', 'path')] [('riscos', None)] [('UserDict', None)] [('popen2', None)] [('popen2', None)] [('popen2', None)] [('copy_reg', '_copy_reg')]