回答編集履歴
1
追記
answer
CHANGED
@@ -52,4 +52,26 @@
|
|
52
52
|
b'\u3075'
|
53
53
|
% python -c 'print("\uFEFFふ".encode("unicode_escape"))'
|
54
54
|
b'\ufeff\u3075'
|
55
|
+
```
|
56
|
+
|
57
|
+
----
|
58
|
+
KSwordOfHaste さんの回答の続きのような形になりますが、
|
59
|
+
|
60
|
+
```plain
|
61
|
+
% echo -n 'あ' | LANG=C python -c 'import sys; print(sys.stdin.read().encode("unicode_escape"))'
|
62
|
+
b'\udce3\udc81\udc82'
|
63
|
+
% LANG=C python -c 'import sys; print(sys.stdin.encoding, sys.stdout.encoding)'
|
64
|
+
US-ASCII US-ASCII
|
65
|
+
```
|
66
|
+
`LANG=C` の設定下だと`sys.stdin`の方も US-ASCII encoding になる影響を受けるので、
|
67
|
+
|
68
|
+
```python
|
69
|
+
sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding="utf-8")
|
70
|
+
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
|
71
|
+
```
|
72
|
+
とするのがいいようです。
|
73
|
+
|
74
|
+
```plain
|
75
|
+
% echo -n 'あ' | LANG=C python -c 'import io, sys; sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding="utf-8"); print(sys.stdin.read().encode("unicode_escape"))'
|
76
|
+
b'\u3042'
|
55
77
|
```
|