TypeError: add_argument() missing 1 required positional argument: 'argument'
时间: 2023-10-24 14:04:50 浏览: 56
This error occurs when the `add_argument()` method of the `ArgumentParser` class is called without specifying an argument.
To fix this error, make sure to pass at least one argument to the `add_argument()` method. The argument should be the name of the command-line argument you want to add.
For example:
```
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--my_arg', help='Description of my argument')
args = parser.parse_args()
```
In this example, we are adding a command-line argument named `--my_arg` with a help message.
相关问题
TypeError: add() missing 1 required positional argument: 'chart'
TypeError: add() missing 1 required positional argument: 'chart'的意思是add()函数缺少一个必需的位置参数'chart'。这意味着在调用add()函数时,没有向其提供所需的参数。可能的原因是函数定义中缺少该参数,或者在调用函数时忘记传递该参数。
以下是一个例子,演示了如何出现TypeError: add() missing 1 required positional argument: 'chart'错误:
```python
def add(x, y):
return x + y
result = add(3)
print(result)
```
在这个例子中,add()函数需要两个参数,但是在调用函数时只传递了一个参数。因此,Python引发了TypeError错误。
要解决这个问题,需要确保在调用函数时传递了所有必需的参数。如果函数定义中确实缺少参数,则需要修改函数定义以包含所需的参数。
TypeError: __init__() missing 1 required positional argument: 'args'
TypeError: __init__() missing 1 required positional argument: 'args'是Python中的一种类型错误。这个错误通常发生在你试图使用一个需要参数的函数或类的时候,但是你并没有传入必需的参数。
举个例子,如果你定义了一个类并在初始化函数中需要传入一个参数,但是在实例化对象时没有传入这个参数,就会出现这个错误。例如:
```
class MyClass:
def __init__(self, arg):
self.arg = arg
obj = MyClass() # TypeError: __init__() missing 1 required positional argument: 'arg'
```
这个错误的解决方法就是在实例化对象时传入所需的参数。例如:
```
obj = MyClass('hello')
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)