私がもし/ else文に2つのまったく同じロジックがあります。if/else文で重複したコードを避ける方法は?
if alert.get('comment_time_created') is None:
here-> args = {'is_comment_visible': 1, 'comment_time_created': current_comment_time}
await self._db_alert.update_alert(alert['alert_id'], **args)
else:
first_comment_time_creation = datetime.strptime(alert['comment_time_created'], '%Y-%m-%dT%H:%M:%SZ')
current_comment_time = datetime.strptime(current_comment_time, '%Y-%m-%dT%H:%M:%SZ')
if current_comment_time > first_comment_time_creation:
await self._db_alert.update_alert(alert['alert_id'], is_comment_visible=1)
else:
here-> args = {'is_comment_visible': 1, 'comment_time_created': current_comment_time}
await self._db_alert.update_alert(alert['alert_id'], **args)
は、かつてこのロジックを実行する方法はありますか?
上記の変数に上記の辞書を保存することはできませんか? – Carcigenicate
これはhttp://codereview.stackexchange.com/にもっと適しているかもしれません。 – kfx
@Carcigenicate説明する方法を教えてください。 –