[New-bugs-announce] [issue32520] error writing to file in binary mode - python 3.6.3
jeff deifik
report at bugs.python.org
Mon Jan 8 10:55:31 EST 2018
New submission from jeff deifik <jeff at jeffunit.com>:
I am running python 3.6.3 on cygwin / windows.
Here is a test program to demonstrate the bug:
#!/usr/bin/env python3
fp = open("bug_out.txt", "ab")
buff = 'Hello world'
print('type of buff is', type(buff))
bin_buff = bytes(buff, 'utf-8')
print('type of bin_buff is', type(bin_buff))
print(bin_buff, file=fp)
Here is the output:
./bug.py
type of buff is <class 'str'>
type of bin_buff is <class 'bytes'>
Traceback (most recent call last):
File "./bug.py", line 8, in <module>
print(bin_buff, file=fp)
TypeError: a bytes-like object is required, not 'str'
The python type system things bin_buff has type bytes, but when I try to print it, the print function thinks it is of type str.
----------
components: IO
messages: 309669
nosy: lopgok
priority: normal
severity: normal
status: open
title: error writing to file in binary mode - python 3.6.3
versions: Python 3.6
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32520>
_______________________________________
More information about the New-bugs-announce
mailing list