LoginSignup
0
0

More than 3 years have passed since last update.

Pythonでimportしたモジュールの明らかに存在するクラスや関数が見つからない時

Posted at

シチュエーション

fooというモジュールを試したいとしましょう。
foo.pyというファイルを作ります。import fooしてfoo.barを呼び出します。
AttributeError: module 'foo' has no attribute 'bar'!!!!!!!!!!!!!!
なぜ!??!!?!???!????

なぜか

import fooで目的のモジュールではなくfoo.py自身を呼び出してしまっているから。スクリプトのあるディレクトリが優先です。(sys.path[0]
play_foo.pyなどの名前を付ける習慣にすると良いでしょう。

0
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
0
0