通常,我知道元组可以用作
(email, username) = ('hello', 'user')
该email将等于hello
但我想知道我能不能做点什么
(email, username) = request.user,所以我不必一直输入request.user,只需像javascript那样使用email和username即可。
如果我执行上面的操作,我会得到一个错误消息,显示为TypeError: object is not iterable
提前感谢您的建议和建议。
发布于 2020-04-11 22:15:07
python中的解构机制使用的“位置”方式工作(就像您在(email, username) = ('hello', 'user')中使用的那样。
它不能以“命名”的方式工作,就像你在(email, username) = request.user中尝试过的那样。
https://stackoverflow.com/questions/61156904
复制相似问题