以下のようなコードを書きました。
2か所エラーがありました。
環境は、Python3.7、Windows10
if cc.endswith(b'stream'):
strpos = f.tell()
while 1:
# lll = f.readline()
lll = fg.next()
ccc = lll.rstrip()
if ccc == 'endstream':まず、1つ目。
fg.next()で、以下のエラー。
AttributeError: 'generator' object has no attribute 'next'Python3系(細かいバージョンは未確認)で、next()から、__next__()に代わっています。
つぎに、2つ目。
ccc = lll.rstrip()で処理が進むと以下のエラー。
File "C:/Users/aaa/PycharmProjects/untitled/test2.py", line 67, in get_imagelist_from_pdf
ccc = lll.rstrip()
AttributeError: 'NoneType' object has no attribute 'rstrip'NoneなTypeが返ってきているのに処理を進めていました。
rstrip()の結果がNoneであるかの判定が必要です。
参考:
https://stackoverflow.com/questions/41203823/attributeerror-nonetype-object-has-no-attribute-strip
修正後コード
if cc.endswith(b'stream'):
strpos = f.tell()
while 1:
lll = fg.__next__()
if lll is not None:
ccc = lll.rstrip()
if ccc == b'endstream':
break
コメント