← index #11099PR #1261
Related · high · value 1.664
QUERY · ISSUE

Binary stdin and stdout buffers for Unix port

openby smurfixopened 2023-03-22updated 2023-03-30
enhancement
$ micropython
>>> import sys
>>> sys.stdout.buffer
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'TextIOWrapper' object has no attribute 'buffer'
>>>

Well, other ports have it … CPython has it … and I'd really like to not have to fall back to open("/dev/stdout","wb") in my unit tests.

Same for stdin of course.

CANDIDATE · PULL REQUEST

stmhal: Implement sys.std{in,out,err}.buffer, for raw byte mode.

closedby dpgeorgeopened 2015-05-13updated 2015-05-27

This is proof of concept (and not necessarily going to be merged) for adding sys.stdin.buffer, sys.stdout.buffer and sys.stderr.buffer objects. These are raw, uncooked, bytes versions of sys.std{in,out,err}.

It costs 170 bytes ROM. See issue #1260 for background.

For comparison with cooked version:

>>> sys.stdout.write('aaa\na')
aaa
a5
>>> sys.stdout.buffer.write('aaa\na')
aaa
   a5
>>> sys.stdin.read(1) # then hit enter as the character to read
'\n'
>>> sys.stdin.buffer.read(1) # then hit enter as the character to read
b'\r'

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied