← index #15098Issue #14218
Off-topic · high · value 4.102
QUERY · ISSUE

mpremote mount fails reading binary file

openby peterhinchopened 2024-05-22updated 2024-05-22
bugtools

Checks

  • I agree to follow the MicroPython Code of Conduct to ensure a safe and respectful space for everyone.

  • I've searched for existing issues matching this bug, and didn't find any.

Port, board and/or hardware

RP2, Pyboard 1.1

MicroPython version

MicroPython v1.22.0 on 2023-12-27; Raspberry Pi Pico with RP2040

Reproduction

Create a file rats15.py on the PC:

import os
fn = "delete_me"
with open(fn, "wb") as f:
    f.write(b"hello\n\xde\xad\xbe\xef")
with open(fn, "rb") as f:
    print(f.readline())
    print(f.read(4))
os.unlink(fn)

Run mpremote

$ mpremote mount .

At the REPL issue

import rats15

Expected behaviour

>>> import rats15
b'hello\n'
b'\xde\xad\xbe\xef'
>>> 

This occurs if the script is run under CPython, under the Unix build, or if run locally on a MP target.

Observed behaviour

When run as described above via mpremote mount .:

MicroPython v1.22.2 on 2024-02-22; Raspberry Pi Pico with RP2040
Type "help()" for more information.
>>> import rats15
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "rats15.py", line 7, in <module>
  File "<stdin>", line 147, in readline
TypeError: unsupported types for __add__: 'str', 'bytes'
>>> 

Additional Information

mpremote is V1.22.0. The fault occurs on readline(). It originally became evident accessing a pgm graphics file which contains four lines of \n terminated ASCII text followed by binary data

CANDIDATE · ISSUE

Support RemoteFile.tell

openby IanLondonopened 2024-03-30updated 2024-03-30
enhancement

Checks

  • I agree to follow the MicroPython Code of Conduct to ensure a safe and respectful space for everyone.

  • I've searched for existing issues regarding this feature, and didn't find any.

Description

It would be nice if RemoteFile implemented tell() -- https://docs.python.org/3/library/io.html#io.IOBase.tell

I ran into this using a 3rd-party library written to support Micropython. Its use of files works fine when you mpremote fs cp the files on to your board, but if you use mpremote mount, it fails with AttributeError: 'RemoteFile' object has no attribute 'tell'. See: https://github.com/bixb922/umidiparser/issues/6

This feature request is somewhat related to #7534, adding an argument for seek

Code Size

I'm not sure

Implementation

  • I intend to implement this feature and would submit a Pull Request if desirable.
  • I hope the MicroPython maintainers or community will implement this feature.
  • I would like to Sponsor development of this feature.

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