AttributeError: 'tuple' object has no attribute 'add_argument'
时间: 2023-06-21 20:06:04 浏览: 593
这个错误通常是由于将元组对象传递给 argparse.ArgumentParser.add_argument() 方法引起的。请确保传递的参数是单独的字符串,而不是元组。例如:
```
parser.add_argument('--foo', help='foo help')
```
如果你传递了一个元组,例如:
```
parser.add_argument(('--foo', '-f'), help='foo help')
```
那么就会出现 'tuple' object has no attribute 'add_argument' 错误。
相关问题
AttributeError: tuple object has no attribute append
这个错误通常发生在你试图将一个元组进行修改的时候,因为元组是不可变的,所以没有 append 方法。
你可以考虑使用列表(list)代替元组(tuple)来进行修改。如果你需要在一个元组中添加元素,你可以创建一个新的元组,包含旧的元组中的元素和新添加的元素。例如:
```python
old_tuple = (1, 2, 3)
new_tuple = old_tuple + (4,)
```
这将创建一个新的元组 `(1, 2, 3, 4)`,而不是修改原始元组。
AttributeError: tuple' object has no attribute 'shape
当出现AttributeError: 'tuple' object has no attribute 'shape'错误时,这通常是因为我们在对一个tuple类型的数据调用成员变量shape时出错。实际上,tuple类型是不可变的,没有shape属性。要解决这个错误,我们需要检查代码中的数据类型是否正确。在错误的用法中,我们可能会看到类似于a = tuple(a)的代码,这会将a转换为tuple类型,但不会改变a的属性。因此,要保存转换后的变量,我们需要声明一个新的变量来保存,例如b = tuple(a)。请注意,b是一个tuple类型,而a的类型保持不变。和这个错误类似的错误还有:AttributeError: 'list' object has no attribute 'shape',AttributeError: 'int' object has no attribute 'shape'等。要注意避免这样的错误用法。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.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)