[Python-checkins] r61018 - python/trunk/Doc/library/modulefinder.rst

georg.brandl python-checkins at python.org
Sat Feb 23 23:05:38 CET 2008


Author: georg.brandl
Date: Sat Feb 23 23:05:38 2008
New Revision: 61018

Modified:
   python/trunk/Doc/library/modulefinder.rst
Log:
Add examples to modulefinder docs. Written for GHOP by Josip Dzolonga.


Modified: python/trunk/Doc/library/modulefinder.rst
==============================================================================
--- python/trunk/Doc/library/modulefinder.rst	(original)
+++ python/trunk/Doc/library/modulefinder.rst	Sat Feb 23 23:05:38 2008
@@ -50,3 +50,65 @@
 
    Analyze the contents of the *pathname* file, which must contain  Python code.
 
+.. attribute:: ModuleFinder.modules
+
+   A dictionary mapping module names to modules. See :ref:`modulefinder-example`
+
+
+.. _modulefinder-example:
+
+Example usage of :class:`ModuleFinder`
+--------------------------------------
+
+The script that is going to get analyzed later on (bacon.py)::
+
+   import re, itertools
+
+   try:
+       import baconhameggs
+   except ImportError:
+       pass
+
+   try:
+       import guido.python.ham
+   except ImportError:
+       pass
+
+
+The script that will output the report of bacon.py::
+
+   from modulefinder import ModuleFinder
+
+   finder = ModuleFinder()
+   finder.run_script('bacon.py')
+
+   print 'Loaded modules:'
+   for name, mod in finder.modules.iteritems():
+       print '%s: ' % name,
+       print ','.join(mod.globalnames.keys()[:3])
+
+   print '-'*50
+   print 'Modules not imported:'
+   print '\n'.join(finder.badmodules.iterkeys())
+
+Sample output (may vary depending on the architecture)::
+
+    Loaded modules:
+    _types:
+    copy_reg:  _inverted_registry,_slotnames,__all__
+    sre_compile:  isstring,_sre,_optimize_unicode
+    _sre:
+    sre_constants:  REPEAT_ONE,makedict,AT_END_LINE
+    sys:
+    re:  __module__,finditer,_expand
+    itertools:
+    __main__:  re,itertools,baconhameggs
+    sre_parse:  __getslice__,_PATTERNENDERS,SRE_FLAG_UNICODE
+    array:
+    types:  __module__,IntType,TypeType
+    ---------------------------------------------------
+    Modules not imported:
+    guido.python.ham
+    baconhameggs
+
+


More information about the Python-checkins mailing list