Python:.pop在相同和不同lin之间的行为不同

2024-05-19 03:20:09 发布

您现在位置:Python中文网/ 问答频道 /正文

有人能解释一下为什么这两个代码段的行为不同吗

这里我得到了预期的输出{datetime.date(2019, 6, 18): 12300}

    events_sales_gross_last_7_days = events_sales_gross_last_7_days_incl_today.get(event.pk, {})
    events_sales_gross_last_7_days.pop(timezone.now().date(), 0)
    print(events_sales_gross_last_7_days)

然而,下一段代码只返回了'int' object has no attribute 'get'

events_sales_gross_last_7_days = events_sales_gross_last_7_days_incl_today.get(event.pk, {}).pop(timezone.now().date(), 0)
print(events_sales_gross_last_7_days)

Tags: eventgettodaydateeventsdayspopnow

热门问题