Я искал альтернативные способы передал информацию классу, например, в кортеже или списке, но не смог найти много информации, которая показалась бы релевантной. Как лучше всего передавать множество переменных в класс в качестве параметров? Или мне вообще не следует использовать класс для подобных вещей?
Я уменьшил количество переменных и кода для наглядности, но вот класс:
Код: Выделить всё
Class GenericEvent:
def __init__(self, type, date_scraped, date_of_event, time, link,
blurb):
countdown_delta = date_of_event - date_scraped
countdown = countdown_delta.days
if countdown < 0:
has_passed = True
else:
has_passed = False
self.type = type
self.date_scraped = date_scraped
self.date_of_event = date_of_event
self.time = time
self.link = link
self.countdown = countdown
self.has_passed = has_passed
self.blurb = blurb
def get_dictionary(self):
event_dict = {}
event_dict['type'] = self.type
event_dict['scraped'] = self.date_scraped
event_dict['date'] = self.date_of_event
event_dict['time'] = self.time
event_dict['url'] = self.link
event_dict['countdown'] = self.countdown
event_dict['blurb'] = self.blurb
event_dict['has_passed'] = self.has_passed
return event_dict
Код: Выделить всё
event_info = GenericEvent(type="Lunar"
date_scraped=30/01/19
date_of_event=28/07/19
time=12:00
link="www.someurl.com"
blurb="Some string.")
Код: Выделить всё
event_info.get_dictionary()
Будем очень признательны за любую помощь или ссылки.
Подробнее здесь: https://stackoverflow.com/questions/554 ... parameters
Мобильная версия