View Single Post
Old 10-17-2013, 10:32 PM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,849
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Trying to put non ascii characters into filenames robustly is impossible, there is a reason calibre itself convert all filenames to ascii. Different kernels and different filesystems encode filenames in different ways. And on some filesystems, these ways can depend system settings.

That said if you are doing it in a limited context and know what encoding to use then just do

filename.encode('utf-8')

assuming filename is a unicode object and not already a bytestring. If it is alreadya byte string then youneed to know what encoding it is in and decode it first like this

filename.decode(encoding).encode('utf-8')
kovidgoyal is offline   Reply With Quote