r/pythonhelp • • Feb 13 '23

which encoding system/machanism is used in python binary read?

I need to read file in binary format-->

 with open("tex.pdf", mode='br') as file:  
fileContent = file.read()
for i in fileContent:
    print(i,end=" ")

so this provide decimal integers which i think it in ascii format but ascii values only have 0-127

and this output display integers greater that 127 (like 225 108 180 193)

Can someone tell me what encoding/machanism used?

2 Upvotes

2 comments sorted by

2

u/Goobyalus Feb 19 '23

https://docs.python.org/3/library/functions.html#open

As mentioned in the Overview, Python distinguishes between binary and text I/O. Files opened in binary mode (including 'b' in the mode argument) return contents as bytes objects without any decoding. In text mode (the default, or when 't' is included in the mode argument), the contents of the file are returned as str, the bytes having been first decoded using a platform-dependent encoding or using the specified encoding if given.

In binary mode, you get raw bytes. You have to decode the bytes yourself. A byte is an integer between 0 and 255.

0

u/[deleted] Feb 13 '23

[deleted]

1

u/Pink-panther-blog Feb 13 '23

thnks for help bro