parsed.org

Tips by tag: ascii

Colorize python source in a terminal by cygnus on Jan 12, 2005 10:10 AM

Use the pycolor tool included with ipython. It will format the source using ASCII codes so it looks pretty in your terminal:

$ pycolor foo.py
asciicommandsipythonlanguagesprogrammingpycolorpythonterminal

In Python you can use the array module to quickly convert ASCII values to a string and back again.

>>> import array
>>> array.array('B', [97, 98, 99]).tostring()
'abc'
>>> array.array('B', 'abc').tolist()
[97, 98, 99]

For more information, read Python Patterns - An Optimization Anecdote.

arraysasciiconversionmodulesoptimizationpython
Remove Control Characters with Perl by xinu on Aug 28, 2008 08:56 AM

With the following code you can be rid of control characters forever:

$string_with_ctrl_characters =~ tr/\040-\176/ /c;
asciicontrolperl
RSS