为什么str.split不接受关键字参数? [英] Why does str.split not take keyword arguments?

查看:139
本文介绍了为什么str.split不接受关键字参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我看来,我遇到过这种奇怪的行为:

I came across this - in my view - strange behaviour:

"a b c".split(maxsplit=1)
TypeError: split() takes no keyword arguments

为什么str.split()不接受关键字参数,即使这很有意义?我在Python2和Python3中都发现了这种行为。

Why does str.split() not take keyword arguments, even though it would make sense? I found this behavior both in Python2 and Python3.

推荐答案

请参见此错误其替代物

str.split()是CPython中的本机函数,因此表现出此处

str.split() is a native function in CPython, and as such exhibits the behavior described here:


CPython实现细节:可能会提供内置的
函数,这些函数的位置参数没有名称,即使它们
出于文档目的被命名,因此
不能由关键字提供。在CPython中,在C中实现的
函数就是这种情况,这些函数使用 PyArg_ParseTuple()来解析其
参数。

CPython implementation detail: An implementation may provide built-in functions whose positional parameters do not have names, even if they are ‘named’ for the purpose of documentation, and which therefore cannot be supplied by keyword. In CPython, this is the case for functions implemented in C that use PyArg_ParseTuple() to parse their arguments.

这篇关于为什么str.split不接受关键字参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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