LoginSignup
1
3

More than 5 years have passed since last update.

n個のオブジェクトをリストで受け取って処理

Posted at

個数が未知のインスタンスを一度に受け取ってメンバを扱いたかった。

ObjList.py
class object:
  def __init__(self, value):
    self.L = value

def integral(ObjList):
  L = 0.0
  for obj in ObjList:
    L += obj.L
  return L

def main():
  obj1 = object(2.0)
  obj2 = object(3.0)

  L = integral([obj1, obj2])
  print(L)

if __name__ == '__main__':
  main()

意外とすっきり書けた。
想定している用途はまた別だけど、ToDoリストやガントチャートの実装に使えそう。

1
3
6

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
3