The decimal module implements fixed and floating point arithmetic using the model familiar to most people, rather than the IEEE floating point version implemented by most computer hardware. A Decimal instance can represent any number exactly, round up or down, and apply a limit to the number of significant digits.
Read more at pymotw.com: decimal
Disclosure: I received a copy of this book for free from Addison-Wesley as part of the PyATL Book Club.
I have a copy of the first edition of the Python Essential Reference that I picked up at IPC 8 back in 2000. It’s largely out of date by now, given that it covered Python 1.5.2. But at the time it was one of the few books I always kept close at hand for easy reference.
The dis module includes functions for working with Python bytecode by “disassembling” it into a more human-readable form. Reviewing the bytecodes being executed by the interpreter is a good way to hand-tune tight loops and perform other kinds of optimizations. It is also useful for finding race conditions in multi-threaded applications, since you can estimate where in your code thread control may switch.
Read more at pymotw.com: dis
I’m working on a PyMOTW post about the dis module. As one of the examples, I’d like to show how to use dis to reduce the number of opcodes processed in a loop as an optimization technique. I’m looking for some “naive” code that looks OK, but doesn’t perform especially well on large datasets.
So far I have a class that reads /usr/share/dict/words and organizes the words by their first letter:
The Practice of Programming by Brian Kernighan and Rob Pike left me a little disappointed. If I had read it at a time closer to when it was originally published in 1999, I may have come away liking the book better. There’s nothing wrong with the advice, and it reads well, but I don’t think the examples are standing the test of time.
It is also possible that I’m just not a good representative of the target audience.
This week’s article on pydoc article on pydoc is the 100th PyMOTW episode. Whew! To coincide with the coverage of pydoc, I have also enhanced the command line script motw that shows the module of the week article for a given module. The plain text output is now generated using the docutils rst-to-text converter (instead of using the rst source as plain text). The pydoc pager is used to display the text, so long articles no longer scroll off of the screen right away.
The pydoc module imports a Python module and uses the contents to generate help text at runtime. The output includes docstrings for any objects that have them, and all of the documentable contents of the module are described.
Read more at pymotw.com: pydoc
The PSF is looking for for companies and organizations that use
Python. Take a few minutes to fill out the survey and help us out!
In Search of Success Stories
Python includes several standard programming data structures as built-in types (list, tuple, dictionary, and set). Most applications won’t need any other structures, but when they do the standard library delivers.
Read more at pymotw.com: articles/data_structures.html
The string class is the most obvious text processing tool available to Python programmers, but there are plenty of other tools in the standard library to make text manipulation simpler.
Read more at pymotw.com: articles/text_processing.html