Python program fails on Windows but not on Linux -


the program below triggers unicodeencodeerror on windows 10 machine (running python 3.5.2) no error @ on linux machine (running python 3.3.2).

#!/usr/bin/python import logging str ="antonín dvořák" logging.basicconfig(filename='log.txt', level=logging.info) logging.info(str) 

on linux, log file correctly contains:

info:root:antonín dvořák 

on windows, following error:

enter image description here

any ideas on possible cause discrepancy?

instead of file name, pass stream encoding specified:

logging.basicconfig(     stream=open('log.txt', 'w', encoding='utf-8'),     level=logging.info ) 

as cause, it's trying open target file using current locale's encoding (cp1252, judging stack trace).


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -