Test if sys.stdout has an encoding attribute

Signed-off-by: Jan Schulz <jasc@gmx.net>