A
A
Alexander Matvienko2022-01-07 15:31:30
Python
Alexander Matvienko, 2022-01-07 15:31:30

Why doesn't if see the word?

with Popen([sys.executable, '-u', 'executer/__main__.py', f'{address} {filename}'],
               stdout=PIPE, universal_newlines=True) as process:
        for line in process.stdout:
            print(line)
            if line == 'stock':
                return


print displays stock, but the check itself does not see it, I tried find, but also without result.
isinstance says it's a string, what's the problem then?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Michael, 2022-01-07
@1na1

Most likely at the end of the line "stuck" the transfer of the correction. A simple solution might be str.rstrip():

# if line == 'stock': # Убрать
if line.rstrip() == 'stock': # Добавить

In general, use the pycharm debugger or another similar one and everything will fall into place, do not guess using print.
If there are problems using the debugger, try using this print. It will show labels along the boundaries of the word and it will be clear what is wrong in it.
# print(line)  # убрать
print(">%s<" % line) # добавить

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question