gpt4 book ai didi

Python 类型错误 : can only concatenate tuple (not "str") to tuple

转载 作者:太空宇宙 更新时间:2023-11-03 18:30:23 27 4
gpt4 key购买 nike

我知道还有其他几个问题提出了完全相同的问题,但是当我运行时: 导入命令 从 pyDes 导入 *

def encrypt(data, password,):
k = des(password, CBC, "\0\0\0\0\0\0\0\0", pad=None, padmode=PAD_PKCS5,)
d = k.encrypt(data,)
return d
def decrypt(data, password,):
k = des(password, CBC, "\0\0\0\0\0\0\0\0", pad=None, padmode=PAD_PKCS5,)
d = k.decrypt(data,)
return d
command1 = commands.getstatusoutput('ifconfig',)
encrypted = encrypt(command1, '12345678',)

我明白了:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in encrypt
File "build/bdist.macosx-10.6-universal/egg/pyDes.py", line 658, in encrypt
File "build/bdist.macosx-10.6-universal/egg/pyDes.py", line 195, in _padData
TypeError: can only concatenate tuple (not "str") to tuple

我再次知道这个问题已经被问过好几次了,但我似乎无法像其他问题一样通过将逗号放在正确的位置来完成这项工作。

最佳答案

该函数需要一个单元素元组作为参数。要在 Python 中明确指定单元素元组,您需要括号:

tuple_containing_only_zero = (0,)   # note the comma!

逗号是 Python 中元组的实际构造函数,因此您可以指定更长的元组,而无需括号:

>>> longer_tuple = 1, 2, 3, 4, 5
>>> longer_tuple
(1, 2, 3, 4, 5)

但是如果你调用一个函数:

f(x, y,)   # is y a 1-tuple or a SyntaxError?

没有括号的一元组会很难看并且不明确。

关于Python 类型错误 : can only concatenate tuple (not "str") to tuple,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22467687/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com