Python 中文轉Unicode字符串

  • 2020 年 1 月 13 日
  • 筆記

Python 3.6

代碼:

# -*- coding: utf-8 -*      def to_unicode(string):        ret = ''      for v in string:          ret = ret + hex(ord(v)).upper().replace('0X', '\u')        return ret      print(to_unicode("中國"))

輸出:

"D:Program Files (x86)Python36-32python.exe" E:/PycharmProjects/Test/test.py  u4E2Du56FD    Process finished with exit code 0