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')
|