Read Unicode characters from command-line arguments in Python 2.x on Windows

后端 未结 4 1091
萌比男神i
萌比男神i 2020-11-27 04:30

I want my Python script to be able to read Unicode command line arguments in Windows. But it appears that sys.argv is a string encoded in some local encoding, rather than Un

4条回答
  •  臣服心动
    2020-11-27 05:05

    Try this:

    import sys
    print repr(sys.argv[1].decode('UTF-8'))
    

    Maybe you have to substitute CP437 or CP1252 for UTF-8. You should be able to infer the proper encoding name from the registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage\OEMCP

提交回复
热议问题