0

I have a string that comes from a process' output, which seems to be unicode, and I can't compare it to a 'normal' string.

Here is the code:

proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
(out, err) = proc.communicate()
result = re.match(r'#title#(?P<title>.*)#artist#(?P<artist>.*)#track#(?P<track>.*)#islive#(?P<islive>.*)', out.decode("utf-8"))
if result:
    print(result.group('islive'))
    print('na')

    print(result.group('islive').lower() == 'na')

The output:

u'NA'
na
False

The python version is Python 3.6.5.

I need some help on how to compare these two strings.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
katona.abel
  • 771
  • 4
  • 12

1 Answers1

0

If comparing to u'na' (which should be preferred due to being faster) is not an option you can utf-8 encode your unicode string before comparing.

proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
(out, err) = proc.communicate()
result = re.match(r'#title#(?P<title>.*)#artist#(?P<artist>.*)#track#(?P<track>.*)#islive#(?P<islive>.*)', out.decode("utf-8"))
if result:
    print(result.group('islive'))
    print('na')

    print(result.group('islive').lower().encode('utf8') == 'na')
Teekeks
  • 196
  • 10