encode
is the wrong method for this: The result of encoding is a binary value, ready to be output to file. What you are thinking of is the decode function, which converts a binary value (back) to a string.
If the string doesn't display properly without encoding (or decoding), then you'll need to figure out which encoding is used, convert the name to a bytestring, and then decode it from the correct type.
Like many languages, Python is starting to conceptualize string handling the right way:
- textual data has no (true) encoding, or byte-semantics. The interpreter uses whatever encoding it wishes, and presents the user with characters. You have to encode it to send it to file (But, there is a default encoding: UTF-8 or locale would both makes sense, and I believe Python chooses UTF-8 for this.)
- binary data has no textual representation: You have to explicitly decode it in order to treat it as text, and that forces you to think about which encoding it is in.