Is there any way I can assign a variable from a complex calculation? I know I can create a function and use that, but sometimes that's overkill. I would like to assign a variable from a complex calculation without declaring a bunch of local variables.
Take these statements for example, I'm only interested in using the 'total_days' variable from now on, but putting the calculation all on a long line is messy:
days_until = (self.last_date - self.first_date).days
opening_time = datetime.combine(self.last_time, EXCHANGE_OPEN_TIME)
time_open = self.last_time - opening_time
ratio = time_open.total_seconds()
/EXCHANGE_OPENING_HOURS.total_seconds()
total_days = days_until + ratio if ratio < 1 else days_until + 1
In my mind, I would like to use something like:
total_days = (
days_until = (self.last_date - self.first_date).days
time_open = self.last_time - opening_time
ratio = time_open.total_seconds()
/EXCHANGE_OPENING_HOURS.total_seconds()
return days_until + ratio if ratio < 1 else days_until + 1
)