Serhiy Storchaka <[email protected]> added the comment:
print() converts all its arguments to string by calling str(). The resulting
strings are written to the output file.
print(bin_buff, file=fp) is equivalent to
fp.write(str(bin_buff))
fp.write('\n')
If you will run Python with options -b or -bb you will get a warning or an
error from str(bin_buff) because this operation can be ambiguous. It is better
to use an explicit repr() for converting bytes to str if you want to get the
representation of the bytes object as a Python literal, or convert it to a
string with specifying explicit encoding: str(bin_buff, 'utf-8') or
bin_buf.decode('utf-8').
----------
nosy: +serhiy.storchaka
resolution: -> not a bug
stage: -> resolved
status: open -> closed
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue32520>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com