LoginSignup
1
0

More than 5 years have passed since last update.

AttributeError: 'module' object has no attribute 'reader'

Last updated at Posted at 2019-01-24
import csv
file = open('/Users/mizuguchitaishi/Documents/data (24).csv')
reader = csv.reader(file)
print(reader)

pythonでcsvモジュールをインポートして実行したら
AttributeError: 'module' object has no attribute 'reader'
というエラーが出た

モジュールを探すとき最も優先されるのはスクリプトのあるディレクトリなので、この場合スクリプトは自分自身をインポートしてることになるらしい。
だから使うモジュールと同じ名前の.pyファイルを作らないように注意しないといけない。
csv.py→csvファイル.pyに変更したら実行できました。

参照
(https://togetter.com/li/2075)

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0