質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

UTF-8

UTF-8は8ビット符号単位の文字符号化形式及び文字符号化スキームです。データ交換方式、ファイル形式としては、一般的にUTF-8が使われる傾向があります。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Parse.com

Parse は BaaS ( Backend as a Service)モバイルアプリ開発のサーバサイド部分を肩代わりしてくれるサービスです

Q&A

0回答

5427閲覧

pythonのparseエラー

yokookentarou

総合スコア11

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

UTF-8

UTF-8は8ビット符号単位の文字符号化形式及び文字符号化スキームです。データ交換方式、ファイル形式としては、一般的にUTF-8が使われる傾向があります。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Parse.com

Parse は BaaS ( Backend as a Service)モバイルアプリ開発のサーバサイド部分を肩代わりしてくれるサービスです

0グッド

0クリップ

投稿2018/07/24 12:22

encoding = "utf-8" infile_xml= open(base_path + gov + '/Annotations/' +file) root = ElementTree.parse(f) cls_names = [] total_images = 0 for gov in govs: file_list = os.listdir(base_path + gov + '/Annotations/') for file in file_list: total_images = total_images + 1 if file =='.DS_Store': pass else: infile_xml = open(base_path + gov + '/Annotations/' +file) tree = ElementTree.parse(infile_xml) root = tree.getroot() for obj in root.iter('object'): cls_name = obj.find('name').text cls_names.append(cls_name) print("total") print("# of images:" + str(total_images)) print("# of labels:" + str(len(cls_names))) ```Traceback (most recent call last): File "/anaconda3/envs/TensorFlow2/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2963, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "<ipython-input-19-13a3872d49bb>", line 3, in <module> root = ElementTree.parse(f) File "/anaconda3/envs/TensorFlow2/lib/python3.6/xml/etree/ElementTree.py", line 1196, in parse tree.parse(source, parser) File "/anaconda3/envs/TensorFlow2/lib/python3.6/xml/etree/ElementTree.py", line 597, in parse self._root = parser._parse_whole(source) File "<string>", line unknown ParseError: no element found: line 1, column 0 上記のコードを打ち込むと no element found: line 1, column 0 とエラーが出てしまいます 環境としてはmacOS High Sierra バージョン10.13.5です 上記のエラーが出てしまうのですが、どのようにすれば改善できるのでしょうか? よろしくお願いします。 ・環境構築に関しては、ネットからanacondaをインストールしました。 今回githubで参考にしているのですがその途中でエラーが出てしまいました。 参考URLはこちらになります https://github.com/sekilab/RoadDamageDetector/blob/master/RoadDamageDatasetTutorial.ipynb 念のため、前の段階の作業コードを載せておきます ```ここに言語を入力 import six.moves.urllib as urllib
>>> import os >>> os.getcwd()
try: import urllib.request except ImportError: raise ImportError('You should use Python 3.x') if not os.path.exists('./RoadDamageDataset.tar.gz'): url_base = 'https://s3-ap-northeast-1.amazonaws.com/mycityreport/RoadDamageDataset.tar.gz' urllib.request.urlretrieve(url_base, './RoadDamageDataset.tar.gz') print("Download RoadDamageDataset.tar.gz Done") else: print("You have RoadDamageDataset.tar.gz")
if not os.path.exists('./trainedModels.tar.gz'): url_base = 'https://s3-ap-northeast-1.amazonaws.com/mycityreport/trainedModels.tar.gz' urllib.request.urlretrieve(url_base, './trainedModels.tar.gz') print("Download trainedModels.tar.gz Done") else: print("You have trainedModels.tar.gz")
!tar -zxf ./RoadDamageDataset.tar.gz !tar -zxf ./trainedModels.tar.gz
from xml.etree import ElementTree from xml.dom import minidom import collections import os import matplotlib.pyplot as plt import matplotlib as matplot import seaborn as sns %matplotlib inline
base_path = os.getcwd() + '/RoadDamageDataset/' damageTypes=["D00", "D01", "D10", "D11", "D20", "D40", "D43", "D44"] # govs corresponds to municipality name. govs = ["Adachi", "Chiba", "Ichihara", "Muroran", "Nagakute", "Numazu", "Sumida"]
encoding = "utf-8" infile_xml= open(base_path + gov + '/Annotations/' +file) root = ElementTree.parse(f) cls_names = [] total_images = 0 for gov in govs: file_list = os.listdir(base_path + gov + '/Annotations/') for file in file_list: total_images = total_images + 1 if file =='.DS_Store': pass else: infile_xml = open(base_path + gov + '/Annotations/' +file) tree = ElementTree.parse(infile_xml) root = tree.getroot() for obj in root.iter('object'): cls_name = obj.find('name').text cls_names.append(cls_name) print("total") print("# of images:" + str(total_images)) print("# of labels:" + str(len(cls_names)))

Traceback (most recent call last):

File "/anaconda3/envs/TensorFlow2/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2963, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)

File "<ipython-input-19-13a3872d49bb>", line 3, in <module>
root = ElementTree.parse(f)

File "/anaconda3/envs/TensorFlow2/lib/python3.6/xml/etree/ElementTree.py", line 1196, in parse
tree.parse(source, parser)

File "/anaconda3/envs/TensorFlow2/lib/python3.6/xml/etree/ElementTree.py", line 597, in parse
self._root = parser._parse_whole(source)

File "<string>", line unknown
ParseError: no element found: line 1, column 0

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

YouheiSakurai

2018/07/25 01:28

問題解決にはroot = ElementTree.parse(f)のfのファイルの中身を確認する必要があります。
yokookentarou

2018/07/25 04:29

fのファイルにinfile_xmlと入れたところ 'utf-8' codec can't decode byte 0xb0 in position 45: invalid start byteと言うエラーが出てしましました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問