[PyQt] Qstring and encode
Kyle Altendorf
sda at fstab.net
Mon Sep 25 02:59:49 BST 2017
Python 3 does have bytes. Note that in Python 2 str is a byte sequence.
https://docs.python.org/3/library/stdtypes.html#binary-sequence-types-bytes-bytearray-memoryview
But what version of Python and PyQt are you working with? And what did you try and what was the full traceback?
Cheers,
-kyle
On September 24, 2017 9:43:29 PM EDT, Phil <phil_lor at bigpond.com> wrote:
>Thank you for reading this.
>
>I retrieve text from a lineEdit like this:
>
>mytext = self.lineEdit.text()
>
>However, I need to convert the string to a byte array for pyserial.
>
>I can use a python string (but not a QString)like this:
>
>mytext = mytext + "\n"
>mybytes = mytext.encode('ascii') # or I can use 'utf-8')
>ser.write(mybytes)
>
>QString doesn't have an encode attribute. How can I overcome this?
>
>I had used bytes(mytext) which worked from within Eric but not from the
>
>command prompt. Apparently, bytes is not part of python3.
>
>--
>Regards,
>Phil
>_______________________________________________
>PyQt mailing list PyQt at riverbankcomputing.com
>https://www.riverbankcomputing.com/mailman/listinfo/pyqt
More information about the PyQt
mailing list