-2

I am new to the os library, and while experimenting with decoding QR codes and extracting only the meaningful part of the output, I received this error:

AttributeError: 'int' object has no attribute 'replace'

At first glance I thought that I should be casting the returned value of the os.system() function, but I received the same error again.

Here's my code:

import os
test = str(os.system("zbarimg *.png"))
test.replace("QR-Code:", "")
print(test)
CDJB
  • 14,043
  • 5
  • 29
  • 55
Feres Hammemi
  • 29
  • 1
  • 1
  • 6
  • 1
    You don't have to accept the first answer that gets close to answering your question. You should wait for a quality answer that actually answers the questions you asked. – jww Dec 10 '19 at 14:46

2 Answers2

0

The os.system() command returns the exit code or status (an integer) of the process, depending on whether your system is Windows or Unix. This is different to what you expect, which is the result of the command zbarimg *.png.

To run a shell command and get it's output, you can check the responses to this question.

CDJB
  • 14,043
  • 5
  • 29
  • 55
-1

You probably need subprocess.check_output() as it allows you to

Run command with arguments and return its output as a byte string.

Sebastian Lore
  • 357
  • 4
  • 23