传递 **kwargs 和尾随逗号的 SyntaxError [英] SyntaxError with passing **kwargs and trailing comma

查看:75
本文介绍了传递 **kwargs 和尾随逗号的 SyntaxError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道为什么这是 Python 3.4 中的 SyntaxError:

I wonder why this is a SyntaxError in Python 3.4:

some_function(
  filename = "foobar.c",
  **kwargs,
)

它在删除 **kwargs 后的尾随逗号时起作用.

It works when removing the trailing comma after **kwargs.

推荐答案

正如 vaultah 所指出的(出于某种原因,他没有费心发布答案),这是 在问题跟踪器上报告,此后已更改.从 Python 3.6 开始,语法将正常工作.

As pointed out by vaultah (who for some reason didn’t bother to post an answer), this was reported on the issue tracker and has been changed since. The syntax will work fine starting with Python 3.6.

明确地说,是的,即使在 *args**kwds 之后,我也希望允许尾随逗号.这就是补丁的作用.—Guido van Rossum

To be explicit, yes, I want to allow trailing comma even after *args or **kwds. And that's what the patch does. —Guido van Rossum

这篇关于传递 **kwargs 和尾随逗号的 SyntaxError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆