【发布时间】:2013-02-18 22:40:20
【问题描述】:
假设我有以下代码:
if request.POST:
id = request.POST.get('id')
# block of code to use variable id
do_work(id)
do_other_work(id)
是否有一个快捷方式(一行代码)可以测试条件块是否为 request.POST 并为条件块分配变量 id 以使用 id 变量?
我读了这个Is there a Python shortcut for variable checking and assignment?,但并没有真正回答我的问题。
【问题讨论】:
-
你能写出这段代码的详细版本吗?我对你的措辞有点困惑。
-
@Blender 我想看看我是否可以做类似于 if request.POST and id = request.POST.get('id')
标签: django variables conditional-statements shortcut