消える私はこのような応答のクラスを定義します。Pythonのクラスのインスタンス変数が
class Response(object):
def __index__(self):
self.country = ""
self.time_human = ""
self.time_utc = ""
self.text = ""
self.time_object = None
self.clean_word_list = []
def parse_line(self, line):
if 'text:' in line[:10]:
self.text = line[7:].strip()
elif 'country: ' in line[:9]:
self.country = line[8:].strip()
elif 'time_human: ' in line[:15]:
self.time_human = line[12:].strip()
elif 'time_utc: ' in line[:15]:
self.time_utc = int(line[10:].strip())
self.time_object = datetime.fromtimestamp(self.time_utc)
私は、テキストファイルから行を読み取り、応答に適切な値を代入する方法があります:
class file_importer(object):
def __init__(self, file_name):
self.file_name = file_name
def get_responses_from_file(self):
directory = DIRECTORY_TO_FILE
formatted_filename = directory + self.file_name
file = open(formatted_filename, 'r')
response = Response()
response_list = []
for line in file:
if line[0] == '*':
response_list.append(response)
response = Response()
else:
response.parse_line(line)
return response_list
を
しかし、get_responses_from_file()が返すresponse_listは、response.clean_word_list属性を持たないレスポンスのリストです。何が起こった?
である必要があります**' __index__' – Wombatz