If a file is opened in "binary", you get a
Assuming a "bytes.dat" file that contains
bytes
object. Otherwise you get a str
object:Assuming a "bytes.dat" file that contains
Déjà vu!\n
(encoded in UTF-8) the following code:with open('bytes.dat','rb') as f: dat=f.read() print(type(dat), len(dat)) with open('bytes.dat','r') as f: dat=f.read() print(type(dat), len(dat))yields:
Output:<class 'bytes'> 11
<class 'str'> 9
Of course, sys.stdin is already opened in text mode, so it reads str
objects and not bytes
. But you can read the binary buffer object sys.stdin is based on. See the note here.
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Your one-stop place for all your GIMP needs: gimp-forum.net