In python 2 a program output is redirected to a file as bytes
-file content---
b'data1'
b'data2'
when reading the file as string I am getting 'b\'data1'\r\n'...
when reading as binary I am getting b'b\'data1\r\n'...
I'd like to have all lines in a list as 'data1'...'data2'
with no leading b
.
I tried the decoding 'utf-8'
but the line is a string with 'b\''
cannot be converted
in pyhon2 I read it like
if not sys.stdin.isatty():
input_file = BytesIO(sys.stdin.read())
but in python3 I tried decoding before print and redirect with pipe works sometimes but sometimes I am having this error
File "Python38-32\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u2011' in position 373877: character maps to <undefined>
Thank.