类型错误:method() 需要 1 个位置参数,但给出了 2 个 - TypeError: method() takes 1 positional argument but 2 were given
问题:
If I have a class...如果我有一堂课...
class MyClass:
def method(arg):
print(arg)
...which I use to create an object... ...我用来创建一个对象...
my_object = MyClass()
...on which I call method("foo")
like so... ...我像这样调用method("foo")
...
>>> my_object.method("foo")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: method() takes exactly 1 positional argument (2 given)
...why does Python tell me I gave it two arguments, when I only gave one? ...为什么 Python 告诉我我给了它两个参数,而我只给了一个参数?
解决方案:
参考一: http://stackoom.com/question/1cT69参考二: TypeError: method() takes 1 positional argument but 2 were given
「其他文章」
- POST 未选中的 HTML 复选框 - POST unchecked HTML checkboxes
- 获得 π 值的最快方法是什么? - What is the fastest way to get the value of π?
- 连接到 MySQL 数据库时关于 SSL 连接的警告 - Warning about SSL connection when connecting to MySQL database
- 如何检查 UITextField 何时更改? - How do I check when a UITextField changes?
- 如何在 Javascript 中开始和结束一天? - How to get start and end of day in Javascript?
- 在 package.json 中查找未使用的 npm 包 - Find unused npm packages in package.json
- 如何在 Linux 中生成带有绝对路径的文件列表? - How can I generate a list of files with their absolute path in Linux?
- 如何将对象添加到数组 - How to add an object to an array
- 检测是通过 require 调用还是直接通过命令行调用 - Detect if called through require or directly by command line
- 如何使用 IntelliJ IDEA 查找所有未使用的代码? - How to use IntelliJ IDEA to find all unused code?
- 如何创建 MySQL 分层递归查询? - How to create a MySQL hierarchical recursive query?
- 计算文件的 MD5 校验和 - Calculate MD5 checksum for a file
- git rebase:“错误:无法统计‘文件’:权限被拒绝” - git rebase: "error: cannot stat 'file': Permission denied"
- 类型错误:method() 需要 1 个位置参数,但给出了 2 个 - TypeError: method() takes 1 positional argument but 2 were given
- 读取和写入文件的最简单方法 - Easiest way to read from and write to files
- `enable_shared_from_this` 有什么用处? - What is the usefulness of `enable_shared_from_this`?
- Docker将什么添加到lxc-tools(用户空间LXC工具)? - What does Docker add to lxc-tools (the userspace LXC tools)?
- 如何在 string.replace 中输入正则表达式? - How to input a regex in string.replace?
- 如何从shell中将一个文件附加到Linux中的另一个文件? - How to append one file to another in Linux from the shell?
- CSS Selector,适用于具有两个类的元素 - CSS Selector that applies to elements with two classes