kekka.py(ファイル名) import human as hu with open("kojin.txt") as rf: lines=rf.readlines() for line in lines: line = line.rstrip('\r\n') self = hu.Human(line)
human.py(ファイル名) from datetime import date class Human: def __init__(self,sei,mei,height,weight,seibetsu,birthday): self.__sei=sei self.__mei=mei self.__height=height self.__weight=weight self.__seibetsu=seibetsu self.__birthday=birthday #成人しているか def method_BirthDay(self): #現在の年からテキスト内の年を引く処理 today=date.today birthday=self.birthday date_delta=today-birthday age=date_delta.days//365 #20を超えているかどうか判定 #if(name>=20): #名前出力#
kojin.txt(テキストファイル中身) #性、名、身長、体重、性別、生年月日 Yamato,Takeru,178,72.0,M,19991006 Shirai,Yuuji,82,8.0,M,20190201 Ogata,Kenji,178,64,M,19990627
2つのファイルを用意しておりテキストファイルの内容を引数として受け渡して利用したいのですがエラーが出てしまいます。
※self = hu.Human(line)のところ
エラー名:init() missing 5 required positional arguments: 'mei', 'height', 'weight', 'seibetsu', and 'birthday'
テキストファイルの中身を活用したいのですが他に良い方法はあるでしょうか
知見のある方、ご教授頂けると幸いです。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/07/02 14:33
2019/07/02 23:32
2019/07/05 10:00