5 page-title: Pylit - Examples
11 The following examples illustrate use cases for "literate programming with
19 Generally, the literate source will not substitute a user guide, but can
20 serve as base documentation as well as a reference.
22 The text parts can be used to structure the script, for additional
23 explanations, documentation of variants and discussion why a specific
27 is a script intended for the "end user". Both, command line
28 and programmatic use is possible.
30 Sources: `pylit.py`__, `pylit.py.txt`__
38 This is used as an introductory example to literate programming
39 in the `LiteratePrograms.org Wiki`_. Riccardo Murri wrote a Python
42 Sources: `99bottles.py`__, `99bottles.py.txt`__
52 Typically, most of a Python modules's documentation is in docstrings as it
53 should be available by pydoc_ (the Python help and module browser utility).
54 Currently, docstrings are treated as code parts by PyLit.
56 However, literate comments can be used to add structure and documentation
57 that is not intended for the end user of a module but for people trying to
58 maintain or extend it (including the original author). Switching to the
59 "text source" representation of the module greatly facilitates the writing
60 of such "literate comments".
62 .. _pydoc: http://docs.python.org/lib/module-pydoc.html
65 is the module providing the state machine used in PyLit.
67 Sources: `simplestates.py`__, `simplestates.py.txt`__
69 __ simplestates.py.html
71 __ simplestates.py.txt
77 is a survey over the various options and attempts to extend
78 an iterator with methods for `peek`, `pushback` or `test of emptiness`.
80 It is also a Python module defining several examples of such rich
83 BTW: Running ``doctest`` on the code source will only run doctests within
84 docstrings. In contrast, ``pylit --doctest`` will detect all doctests, in
85 docstrings as well as in text blocks.
87 Sources: `iterqueue.py`__, `iterqueue.py.txt`__.
96 Test suites are a good example for the advantages of literate programming.
97 Documenting the rationale and design as well as test considerations can help
98 a lot when maintaining and extending the suite.
100 The following unit test modules are tested using the nose_ unit
101 test discovery & execution framework. (They should be compatible to
104 .. _nose: http://somethingaboutorange.com/mrl/projects/nose/
105 .. _py.test: http://codespeak.net/py/current/doc/test.html
108 `simplestates_test.py`__
109 is not only the unit test module for simplestates.py,
110 it also defines and tests variants of the state machine class.
112 Sources: `simplestates_test.py`__, `simplestates_test.py.txt`__.
114 __ simplestates_test.py.html
115 __ simplestates_test.py
116 __ simplestates_test.py.txt
119 contains the unit tests for the ``pylit.py`` text <--> code converter
121 Sources: `pylit_test.py`__, and `pylit_test.py.txt`__.
123 __ pylit_test.py.html
128 `iterqueue_test.py`__
129 tests the functionality of the iterator wrapper classes defined in
132 Sources: `iterqueue_test.py`__, `iterqueue_test.py.txt`__.
134 __ iterqueue_test.py.html
136 __ iterqueue_test.py.txt
139 `iterqueue_speed_test.py`__
140 Profiling of the iterator wrapper classes defined in
143 Sources: `iterqueue_speed_test.py`__, `iterqueue_speed_test.py.txt`__
145 __ iterqueue_speed_test.py.html
146 __ iterqueue_speed_test.py
147 __ iterqueue_speed_test.py.txt
153 A tutorial is clearly more of a text document than a program. But usually, a
154 lot of example code gets included. Converting the text source to commented
155 code, it is easier to copy or paste code examples to and from scripts or an
156 interactive program session. Re-converting indents the code snippets
157 correctly so they will be literal blocks in the pretty print.
159 `ginac-tutorial.py`__
160 is an adaption of the `GiNaC tutorial`_ for doing Computer algebra with
161 GiNaC_ and the Python_ programming language using the swiginac_ wrapper
164 It is a work in progress, not completed yet.
166 Sources: `ginac-tutorial.py`__, `ginac-tutorial.py.txt`__
168 __ ginac-tutorial.py.html
169 __ ginac-tutorial.pyr2w
170 __ ginac-tutorial.py.txt
172 .. _`GiNaC tutorial`: http://www.ginac.de/tutorial/
173 .. _GiNaC: http://www.ginac.de
174 .. _Python: http://www.python.org
175 .. _swiginac: http://swiginac.berlios.de
176 .. _LiteratePrograms.org Wiki:
177 http://en.literateprograms.org/LiteratePrograms:Welcome