0

Hello I am having an issue with PyQt when it comes to splitting an string.

I am currently grabbing the input text from a TextEdit field and splitting the string inputted into a list.

    start_token = self.serialInputText.toPlainText()
    split_start = start_token.split(' ')
    print start_token + '\r\n'
    print split_start

However whenever I print this to see what my new string list is I get the following:

<PyQt4.QtCore.QStringList object at 0x10b18a488>

Which i believe is the memory address of the StringList. Instead I would like to print the StringList out and view it to make sure it is functioning correctly.

I have tried a different approach and imported import sip and used sip.setapi("QString", 2) and then when i print my StringList it will appear as the following:

[u'Dog', u'Cat', u'Bird', u'Animals', u'Tigers', u'Etc']

which is fine however it's adding a u to every entry in the list.

Simply put, I want to have a TextEdit field and text will be inputted into that field. Then that text needs to be separated via a space delimiter to be used for another function later on in the program.

JeanP
  • 406
  • 9
  • 27
  • 1
    the `u'string'` just means it's unicode - normal for gui toolkits, and works just like a regular string. as far as the address - unlike many other languages, objects in python tend to have built-in visualizers via `repr` or `str` (or sometimes it's in the console). for 'foreign' objects, that's usually the default representation. in short, everything is probably right, and you're just getting thrown off by visualization artifacts. – Corley Brigman Sep 08 '15 at 13:25
  • Okay thank you, I'm new to python and PyQt I had was confused by the visualization. Thanks! – JeanP Sep 08 '15 at 13:27
  • 1
    @JeanP. That was a very good idea to use `sip.setapi`, as it will save you at lot of hassle in the long run (you should also consider doing the same thing for `QVariant`). However, it would be even better if you used python3, as you will get the same behaviour by default (i.e. no need to use sip). And as an extra bonus, there's no `u` prefixes in python3. – ekhumoro Sep 08 '15 at 14:15
  • @ekhumoro I was thinking of using Python 3 however all of my program's core was made on python 2.7 and the Im still fairly new so i didnt wanna go back and forth between these two versions. I will start using Python3 in my future projects though. Thank you for the tip for `QVariant` – JeanP Sep 08 '15 at 14:17

0 Answers0