print statement: battle with UnicodeEncodeError

Category: Python - Miscellaneous

I received UnicodeEncodeError when playing with various codepages in source code/files/standard streams.
Sometime I receive UnicodeEncodeError when script launched via scheduler or in long running batch when parsing unpredictable [alien ;)] HTML.

Function console() helps avoid this exceptions by converting erroneous charatcters to standard python representation.

to do in future: make a codec-wrapper for safe using in statements like this:

sys.stdout=codecs.getwriter('cp866')(sys.stdout) Date: 11 February, 2012


Sysadmin

Homepage: http://code.activestate.com/recipes/523011-print-statement-battle-with-unicodeencodeerror/?in=lang-python

Developer: Denis Barmenkov

License: Python License

Operating System: Windows

Add a Comment

all are required fields

     
What do you think of this resource?

Select Your Rate:

Votes:0

 

Related Scripts Download

Internet Billing Wizard 1.

developer Developer: http://tekmanproductions...
license License: Freeware
operating systems Operating System: Unix


Calculates IOPS for all disks in Linux/Unix system.

developer Developer: Slava Yanson
license License: Freeware
operating systems Operating System: Windows


RSH sometimes hangs if it cannot resolve to a given host.

developer Developer: Shrinidhi Rao
license License: Freeware
operating systems Operating System: Windows


System administrators sometimes need to automate commands which prompt for a password (or any other single prompt) before they execute.

developer Developer: John Landahl
license License: Python License
operating systems Operating System: Windows


Takes a stream of numbers and outputs simple ASCII graphs of those numbers.

developer Developer: Drew Gulino
license License: Freeware
operating systems Operating System: Windows


A Python script that runs arbitrary Python scripts in an input loop.

developer Developer: Drew Gulino
license License: Freeware
operating systems Operating System: Windows


LoggingWebMonitor listens for log records sent from other processes running in the same box or network.

developer Developer: Gabriel Genellina
license License: Freeware
operating systems Operating System: Windows


To access an XML-RPC server through a proxy which requires authentication, you need to define a custom transport.

developer Developer: Vaibhav Bhatia
license License: Python License
operating systems Operating System: Windows


Takes a sequence and yields K partitions of it into training and validation test sets.

developer Developer: John Reid
license License: Python License
operating systems Operating System: Windows