Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #1/usr/bin/env python
- # this is from The Python
- # Standard Library by example
- # ISBN13: 9780321767349
- import binascii
- def to_hex(t, nbytes):
- """Format text t as a sequence of nbyte long values
- seperated by spaces.
- """
- chars_per_item = nbytes * 2
- hex_version = binascii.hexlify(t)
- return ' '.join(
- hex_version[start:start + chars_per_item]
- for start in xrange(0, len(hex_version), chars_per_item)
- )
- if __name__ == '__main__':
- print to_hex('abcdef', 1)
- print to_hex('abcdef', 2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement