I recently started to use Python 3 and I understood that in this version, the print() function assumes that the string is unicode and not ASCII (8-bit chars).
Well, I know that my strings are sometimes ASCII, but I really don't care about it. Why should I always get an annoying b' prefix printed to the screen?
Is there a way to turn off this "feature" ?
My code:
proc = subprocess.Popen(diff_cmd, shell = True, stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
while proc.poll() is None:
output = proc.stdout.readlines()
for line in output:
print(line)
You need to be explicit about this yourself.
You need to specify the encoding and decode the bytes into Unicode (ASCII encoding): line.decode('ascii'). If object are sometimes bytes and sometimes Unicode then you need to handle this accordingly.
After that you can pass it to print().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With