Why file.readall() removed from frimware 2.6!!

General discussion about topics related to OpenMV.
Posts: 32
Joined: Wed Sep 13, 2017 3:16 am

Why file.readall() removed from frimware 2.6!!

Postby marcus007 » Mon Dec 11, 2017 11:16 pm

Today When I updated my OpenMV to Latest IDE with Latest Firmware I found that file.readall is not working at all , earlier it was working fine but now it raises an error

Code: Select all

"TextIOWrapper object has no attribute 'readall' " 
please do let me know what its substitute now
User avatar
Posts: 2116
Joined: Sun May 24, 2015 2:10 pm

Re: Why file.readall() removed from frimware 2.6!!

Postby kwagyeman » Tue Dec 12, 2017 12:49 am

Mmm, that would be an MicroPython Hal change. Let's see the API:

It looks like you have everything here:

https://github.com/micropython/micropyt ... ile.c#L234

Code: Select all

STATIC const mp_rom_map_elem_t rawfile_locals_dict_table[] = {
    { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) },
    { MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) },
    { MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) },
    { MP_ROM_QSTR(MP_QSTR_readlines), MP_ROM_PTR(&mp_stream_unbuffered_readlines_obj) },
    { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
    { MP_ROM_QSTR(MP_QSTR_flush), MP_ROM_PTR(&mp_stream_flush_obj) },
    { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&file_obj_close_obj) },
    { MP_ROM_QSTR(MP_QSTR_seek), MP_ROM_PTR(&mp_stream_seek_obj) },
    { MP_ROM_QSTR(MP_QSTR_tell), MP_ROM_PTR(&mp_stream_tell_obj) },
    { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&file_obj_close_obj) },
    { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&mp_identity_obj) },
    { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&file_obj___exit___obj) },
And most of those methods are defined here:

https://github.com/micropython/micropyt ... y/stream.c

So, I'd use the readline() method to read one line in a loop. The readlines() method will return all lines in the file but that will cause you to likely run out of RAM given the file size.

Question, is the file a binary file? If so, then readAll() may still work on it. What mode did you open the file in?

Return to “General Topics”

Who is online

Users browsing this forum: Bing [Bot] and 5 guests