Colored text in Python using ANSI Escape Sequences
Posted: June 23, 2008 Filed under: NEZzen Leave a comment »Check it out – pretty.py is a miniature library that provides a Python print and stdout wrapper that makes colored terminal text easier to use (eg. without having to mess around with ANSI escape sequences). This code is public domain – there is no license except that you must leave the header intact.
Just import the module and make use of the printc(), writec(), or switchColor() functions in your own programs. A test sequence is included and can be invoked if you execute the script directly. Source code is after the break…
Mini Hashlib Replacement for Jython and Python below 2.5
Posted: June 19, 2008 Filed under: NEZzen Leave a comment »I’m back! I’d like to resume things here by giving you a solution to a problem others seem to have had (after searching online). It seems that Jython, a popular implementation of Python in Java, does not have Python 2.5′s hashlib module. This posed a problem to me when I was coding a small Jython application that needed one-way hashing.
Python has now-deprecated md5 and sha modules, so I was able to write a small wrapper for the hexdigest() functionality of the md5 and sha1 objects in hashlib. You are welcome to use the code all you’d like, and feel free to expand on it and send back the changes. Source code is after the jump…