tkMath,
convert between pixels, inches, cm and mm
If you're writing some Tkinter software and you're sizing something in
inches or centimeters and tkinter only gives you feedback in pixel
distances then you may need a way to get back to your prefered units of
measure. I recently found myself in this situation. There's nothing
fancy about the set of functions here, it's more about the little known
winfo_fpixels() function. Once you know about this everything else is a
piece of cake. These functions are simple, but convenient.
Win
Services helper
A simple way to implement Windows Service.
using
pyHook to block Windows Keys
Normally you do NOT want to block operating system key combinations but
there are a few legitimate cases where you do. In my case I am making a
pygame script for my 1 year old to bang on the keyboard and see/hear
shapes/color/sounds in response. Brian Fischer on the pygame mailing
list pointed me to pyHook. This example was taken from here:
http://www.mindtrove.info/articles/pyhook.html and modified to use the
pygame event system.
Backup
your files
Makes backup versions of files
Size
of Python objects (revised).
This recipe is an enhancement of recipe #544288 to determine the size of
Python objects in bytes, The main differences are (1) classes and
instances are handled separately, (2) old-style classes are treated as
new-style ones, (3) a simple profile of the objects can be printed, and
(4) 8 functions plus 1 class are exposed by this module. More
information can be found in the documentation and the examples.
List
classes, methods and functions in a module
The recipe provides a method "describe" which takes a module as argument
and describes classes, methods and functions in the module. The
method/function description provides information on the function/method
arguments using the inspect module.
Prime
sieve generators
Two simple generators for generating prime numbers using a prime sieve.
gen_sieve(n) will produce all prime numbers <n, and gen_infsieve()
will infinitely produce prime numbers.
isprime is an example of how one could use gen_sieve: a quick function
for testing primality by attempting modulo division with each potential
prime factor of a number.
Automate
CATIA V5 with Python and Pywin32
This is small application shows how to automate the CAD/PLM Software
CATIA V5 via win32com. CATIA V5 must be installed and should be running
when testing the application. Other examples you can find on
http://win32com.goermezer.de/content/view/29/291/ .
JSON
RPC Server and client
This recipe shows how to create JSON RPC client and server objects. The
aim is to mimic the standard python XML-RPC API both on the client and
server sides, but using JSON marshalling. It depends on cjson
(http://pypi.python.org/pypi/python-cjson) for the encoding/decoding of
JSON data. This recipe tries to reuse the code of XML-RPC as much as
possible.
Create
single-file executables for windows
This windows batch script uses python and py2exe to create a single,
distributable .exe of your python code.
decorator
for doctests
This "tested" decorator assigns decorated_function.test() to call
doctest.run_docstring_examples appropriately.
Indirect
insertion of value to a list
The code to insert a value to a list indirectly ordered by an extra
index list is useful by itself.
Mixing
features of "tree" and of "md5sum" : tree_md5 :)
Have you ever wanted to describe a filesystem subtree with, as an extra
bonus, the md5sum of each file ?
I have.
Here is a tiny Python script that mixes functions of "tree" and of
"md5sum", just for your pleasure.
I wrote it with Python 2.4 under Linux.
Case-insensitive
string replacement
Python does not have case-insensitive string replacement built into the
default string class. This class provides a method that allows you to
do this.
remove
directories recursively
Extremely simple bit of code to remove a directory recursively.
Simply feed it the path of the top-level directory to remove, and off it
goes.
As presented, there is no error-checking; failure at any point will stop
the function and raise an IOError.
Unsupported
sitecustomize.py sinze Python 2.5
Since Python 2.5 the automatic import of the module "sitecustomize.py"
in the directory of the main program is not supported any more (even if
the documentation says that it is). Putting this little script named
"sitecustomize.py" in the default Python path like in "site-packages"
should solve this problem.
gzip
pipe for asynchronous use
I've written a small class to handle a gzip pipe that won't read the
whole source file at once, but will deliver small chunks of data on
demand.
Meta
programming for generating combination (anagram) of a string
making a program that will write a program to find all the combinaison
of a string
Convert
Wordpress Export File to multiple html files
Converts Wordpress Export Files (XML) to multiple html files and
optionally uses tags and authors to create a directory structure.
|