iprint - Andrew "Tridge" Tridgell's iprint in Python

Following code does the same thing that Tridge’s iprint.c does. :-\)

**#!/usr/bin/env python
**


import sys

** “iprint - Andrew \“Tridge\” Tridgell’s iprint in Python”**


def toBinary(dec):
”“”
This function does the coversion from integer to binary
”“”
bin = “
while dec:
bin = (dec % 2 and ‘1’ or ‘0’) + bin
dec = long(dec/2)
return bin or ‘0’


x = 1
text = “
while len(sys.argv) > 1 and x < len(sys.argv):
text += sys.argv[x]
x += 1


for x in text:
print ord(x), “\t”, hex(ord(x)), “\t”, oct(ord(x)), “\t”, toBinary(ord(x)), “\t”, x
print “\n”