![](/img/trans.png)
[英]Hello, i have a text file that i want to write in UTF-16 unicode using python
[英]I want to generate the unicode UTF-16 for a text file in python
完全没用:
==> type .\SO\62111029.py
import io localOutputPath = r'd:\\bat\\62111029input.txt' localUtf16Path = r'd:\\bat\\62111029output.txt' data = [] with io.open(localOutputPath, mode="r", encoding="utf-8") as infile: with io.open(localUtf16Path, mode="w", encoding="utf-8") as outfile: for line in infile: data = ''.join(['\\\\u\u0026#39; + '{:04x}'.format(ord(letter)) for letter in line.rstrip('\\n')]).replace('\\\ ',' ') outfile.write(data + '\\n')
==> 2>NUL del 62111029output.txt
==> type 62111029input.txt
September 1, 1939 1 Σεπτεμβρίου 1939 1 сентября 1939 1. září 1939
==> .\SO\62111029.py
==> type 62111029output.txt
\u0053\u0065\u0070\u0074\u0065\u006d\u0062\u0065\u0072 \u0031\u002c \u0031\u0039\u0033\u0039
\u0031 \u03a3\u03b5\u03c0\u03c4\u03b5\u03bc\u03b2\u03c1\u03af\u03bf\u03c5 \u0031\u0039\u0033\u0039
\u0031 \u0441\u0435\u043d\u0442\u044f\u0431\u0440\u044f \u0031\u0039\u0033\u0039
\u0031\u002e \u007a\u00e1\u0159\u00ed \u0031\u0039\u0033\u0039
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.