summaryrefslogtreecommitdiffstats
path: root/Doc/library
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-02-23 22:05:38 (GMT)
committerGeorg Brandl <georg@python.org>2008-02-23 22:05:38 (GMT)
commitffada76d04535ecc5b58aeaf6e152217b07df033 (patch)
tree367abc5b992c44d191f53c1d86e3933061d36181 /Doc/library
parent7d009926adb7d9079fff2263d37bf3943c373c7b (diff)
downloadcpython-ffada76d04535ecc5b58aeaf6e152217b07df033.zip
cpython-ffada76d04535ecc5b58aeaf6e152217b07df033.tar.gz
cpython-ffada76d04535ecc5b58aeaf6e152217b07df033.tar.bz2
Add examples to modulefinder docs. Written for GHOP by Josip Dzolonga.
Diffstat (limited to 'Doc/library')
-rw-r--r--Doc/library/modulefinder.rst62
1 files changed, 62 insertions, 0 deletions
diff --git a/Doc/library/modulefinder.rst b/Doc/library/modulefinder.rst
index 334bd5d..b0e2bd1 100644
--- a/Doc/library/modulefinder.rst
+++ b/Doc/library/modulefinder.rst
@@ -50,3 +50,65 @@ report of the imported modules will be printed.
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
+
+