How to convert str to unicode python

1

I have to do a comparison between 2 items, one is in unicode, and the other is in str, and what is str is an array.

for bloqueiosPermanentes in arquivo:
    self.blocks.append(bloqueiosPermanentes.replace("\n", ""))

This is how append is made in the variable blocks ..

after

 for n in j['userList']:
    nicks.append(n['nick'])

This is how append is done in variable nicks, it gets its value from a json file pulled from the internet.

The error occurs in the following comparison

for o in nicks:
    if o==self.lblNick.text(): << dá erro aqui na comparacao dos formatos
        pass
    else:
        if o in self.blocks: <<< dá aqui o erro aqui na comparacao dos formatos
            pass

I've tried using .toUtf8 () and unicode (variable) but none of them worked out, all are not allowed

    
asked by anonymous 19.10.2016 / 16:35

1 answer

0

You can convert the value str to unicode like this:

self.blocks.append(unicode(bloqueiosPermanentes.replace("\n", "")))

Or you can do this conversion when comparing:

if o == unicode(self.lblNick.text()):
# ...
if o in map(unicode, self.blocks):
    
21.10.2016 / 22:46