【发布时间】:2020-04-02 09:18:40
【问题描述】:
我目前正在将我的代码从 Python 2 迁移到 Python 3。我使用 Django,看起来我错过了一些东西。
我正在使用来自 Django 的装饰器 @method_decorator(func)。我的功能是这样定义的:
@decorator
func(action_meth, *args, **kwargs):
result = action_meth(*args, **kwargs)
# do
# something
# with
# result
我的问题是 Python 2 和 Python 3 中的 args 值不一样,然后 args 不能用作我的 action_meth 的参数(我得到错误:action_meth 需要 2 个位置参数,但给出了 3 个)
首先,这段代码在 Python 2 中运行良好。但我在互联网上找不到任何关于 Python 3 迁移的信息。 我也很确定它来自 Django 的 method_decorator ......所以有人知道这个功能是否有任何变化吗?
这是我能得到的样本,
在 Python 2 中:
打印(args) => ([u'ID'],)
在 Python 3 中:
打印(args) => SELECT fieldA,fieldB, ...., fieldZ ....; args=(ID,)
感谢您的宝贵时间!
【问题讨论】:
标签: django python-3.x python-2.7 migration