我有一个名为roleName
的PySide2.QtCore.QByteArray
对象,它编码了一个python字符串:
propName = metaProp.name() // this is call of [const char *QMetaProperty::name() ](https://doc.qt.io/qt-5/qmetaproperty.html#name)
// encode the object
roleName = QByteArray(propName.encode())
print(roleName) // this gives b'myname'
// now I would like to get just "myname" without the "b"
roleString = str(roleName)
print(roleString) // this gives the same output as above
我怎样才能找回我的解码字符串?在
在Python3中,将类似字节的对象转换为文本字符串时,必须指定编码。在PySide/PyQt中,这适用于
QByteArray
,其方式与对bytes
相同。如果不指定和编码,str()
的工作方式与repr()
类似:有几种不同的方法可以转换为文本字符串:
^{pr2}$最后一个示例特定于
QByteArray
,但前两个示例应该可以处理任何类似于对象的字节。在相关问题 更多 >
编程相关推荐