LoginSignup
0
0

More than 3 years have passed since last update.

takes 0 positional arguments but 1 was given

Posted at

原因

pythonはクラスメソッドの引数1つ目に必ず self を取らなければならない。というルールがある。

クラス外から任意のクラスメソッドを呼び出す場合は暗黙的に引数 self が渡される。
そのため、受け側で self を第1引数に取るように作っていない場合、こういうエラーになる。

class Sample:
  def test():
    print('x')

Sample().test()

>>実行結果
TypeError: create_dtl_list() takes 0 positional arguments but 1 was given

呼び出し側は引数を渡していないのに、渡したことになっている。(暗黙的にselfを渡している。)

対処法

クラスメソッド定義時には必ず、self を第1引数に入れるようにする。

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