作者热门文章
- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
这被证明是向 python 的粗略过渡。这是怎么回事?:
f = open( 'myfile', 'a+' )
f.write('test string' + '\n')
key = "pass:hello"
plaintext = subprocess.check_output(['openssl', 'aes-128-cbc', '-d', '-in', test, '-base64', '-pass', key])
print (plaintext)
f.write (plaintext + '\n')
f.close()
输出文件如下所示:
测试字符串
然后我得到这个错误:
b'decryption successful\n'
Traceback (most recent call last):
File ".../Project.py", line 36, in <module>
f.write (plaintext + '\n')
TypeError: can't concat bytes to str
最佳答案
subprocess.check_output()
返回一个字节串。
在 Python 3 中,unicode (str
) 对象和 bytes
对象之间没有隐式转换。如果你知道输出的编码,你可以.decode()
得到一个字符串,也可以把你要添加的\n
转成字节
和 "\n".encode('ascii')
关于python - 无法将字节连接到 str,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21916888/
我正在开发一个 voip 调用应用程序。我需要做的是在接到来电时将 Activity 带到前台。我在应用程序中使用 Twilio,并在收到推送消息时开始调用。 问题是我试图在接到任何电话时显示 Act
我是一名优秀的程序员,十分优秀!