开发者

How can I convert a UTF-16 encoded string to an encoding suitable for a Mac OS X filename?

开发者 https://www.devze.com 2023-03-25 07:47 出处:网络
I have a Localized.strings (UTF-16) file that contains some strings that I use to gen开发者_运维知识库erate filenames for.I open the file in python with codecs.open(\"Localized.strings\", \"r\", \"utf

I have a Localized.strings (UTF-16) file that contains some strings that I use to gen开发者_运维知识库erate filenames for. I open the file in python with codecs.open("Localized.strings", "r", "utf-16")

The files are created successfully but with a '?' tacked onto the end of the filename, for example:

MainMenu.strings? - where the "?" is lingering from the previous encoding I assume.

I've tried filename_string.encode('UTF-8') and filename_string.encode('ascii') with no luck, any suggestions? Am I using these wrong?


OK, when reading lines from a file, it's advisable to always strip() or rstrip() them. :)

0

精彩评论

暂无评论...
验证码 换一张
取 消