I need to output some strings (to stdout) and because windows console works in cp437, if the string contains any characters outside cp437, an exception is thrown.
I got around this by
encoding=sys.stdout.encoding
pathstr = path.encode(encoding,errors="replace").decode(encoding)
print(pathstr)
where path is the str i want to output. I'm fine with characters replaced by "?"
This doesn't seem good because it converts to a byte array and back to a str.
Is there a better way to achieve this?
I'm still new to python ( a week maybe ) and I'm using Win7 32 bit with cpython 3.3