Fix function call
Enable support for both Python2 and Python3.

Adds new to_bytes() function that's used to ensure unicode objects are
encoded before being written to pipes.

Also replaces use of print statement with a direct write to standard
out.
Remove trailing whitespace