More Than Just ASCII Digits

Python’s int() converts more than just ASCII digits. It also converts decimal digits from other scripts.

>>> int('42')
>>> int(u'୨୩')

It’s also possible to mix differnt scripts. int() only cares about the decimal value of each digit character.

>>> int(u'௧౩౩೭')

The following snippet creates CSV data for all digits int() can convert:

#!/usr/bin/env python
# coding: utf8
from __future__ import absolute_import, division, print_function
import sys
import unicodedata

def main():
    for i in xrange(sys.maxunicode + 1):
            character = unichr(i)
            value = int(character)
        except ValueError:
                    character, value, i,

if __name__ == '__main__':

And here’s the table generated by that script:

Read more... version 0.0.2

A software I use from time to time but a source code I haven’t touched for almost ten years, except for changing some small things when moving from a private Subversion repository to a public Mercurial one hosted at Bitbucket.

There is no new functionality, just updated the code which was written with ancient Python 2.3 in mind. Some modules where deprecated (md5 and sha1), command line handling is now done with argparse, and the Checksums class was replaced by a function because a class with just __init__() and one other method usually isn’t a real class but just a function in disguise. Quite a poor design choice I’ve made ten years ago. :-)

The doc target is gone from the Makefile because epydoc seems to be dead.

Source code can be found at the project’s page at Bitbucket.

PySensors now under LGPL

I’ve got an email asking why PySensors, a Python binding to libsensors, is released under the GPL. It was because it was written to use the two latest libsensors APIs (3 and 4) and the shared library for the next to last API version is GPL licensed.

The latest API was introduced in 2010 and the libraries for that are dual licensed: GPL or LGPL. So I decided supporting only the latest API version and relicensing the Python bindings to LGPL.

Removing the code for API 3 made the package much simpler. Before there was the __init__ module wich imports common stuff for both APIs and a sub module for each API version. The api3 module is gone now, and contents of common and api4 moved into the __init__ module.

Changes in package structure (red=deleted, gray=moved):

digraph changes { node [shape=box]; edge [dir=none];  "sensors"; subgraph {     rank=same;      "__init__";     "api3" [color=red];     "api4" [color=gray];     "common" [color=gray];     "cli";     "stdc"; }  "sensors" -> "__init__"; "sensors" -> "api3" [color=red]; "sensors" -> "api4" [color=gray]; "sensors" -> "common" [color=gray]; "sensors" -> "cli"; "sensors" -> "stdc";  "api4" -> "__init__" [color=gray, dir=forward]; "common" -> "__init__" [color=gray, dir=forward]; }