teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

2

元のソースコードにスタイルを合わせるよう修正。

2018/07/23 07:57

投稿

tachikoma
tachikoma

スコア3601

answer CHANGED
@@ -2,8 +2,8 @@
2
2
  ```Python
3
3
  encoding = "utf-8"
4
4
  # encoding = "cp932" # utf-8がだめならこっちを試してみてください。
5
- with open("filename.xml", encoding=encoding) as f:
5
+ f = open("filename.xml", encoding=encoding)
6
- root = ElementTree.parse(f)
6
+ root = ElementTree.parse(f)
7
7
  ```
8
8
  文字コードのトラブル
9
9
  * [https://teratail.com/questions/137252](https://teratail.com/questions/137252)

1

追記

2018/07/23 07:57

投稿

tachikoma
tachikoma

スコア3601

answer CHANGED
@@ -1,6 +1,8 @@
1
1
  ファイルを開く際に文字コードを教えてやるとうまくいくかもしれません。
2
2
  ```Python
3
+ encoding = "utf-8"
4
+ # encoding = "cp932" # utf-8がだめならこっちを試してみてください。
3
- with open("filename.xml", encoding="utf-8") as f:
5
+ with open("filename.xml", encoding=encoding) as f:
4
6
  root = ElementTree.parse(f)
5
7
  ```
6
8
  文字コードのトラブル