我希望这会奏效。但事实并非如此。我错了什么?
from PyQt5.QtCore import QByteArray
str = 'foobar'
b = bytes(str, 'UTF-8')
print (b)
print (len(b))
arr = QByteArray(len(b), b)
但我明白了:
b'foobar'
6
Traceback (most recent call last):
File "pyqt_wtf_again.py", line 9, in <module>
arr = QByteArray(len(b), b)
TypeError: bytes or ASCII string of length 1 expected
这应该不起作用吗?