Skip to content

Iterating io objects #177

Closed
Closed

Description

@toddrjen

The read_all_blocks method has a problem for large files: it requires loading all blocks into memory at the same time. If implement #176 and add a read_all method in BaseIO, I would also suggest we implement an __iter__ method. This would just read each object in read_all one-at-a-time. In BaseIO, read_all would just be list(iter(self)), and __iter__ would just be iter([self.read()]), but one or both of these could be overrided in other classes. This would allow a user to just do

for obj in ioobj:
   do_something(obj)

This would be a good parallel to the built-in:

for line in fileobj:
   do_something(fileobj)

So people reading standard python docs will be able to easily translate it into neo without needing to know or care about the details of the IO class.

Activity

  1. samuelgarcia commented on Jul 21, 2014

    @samuelgarcia
    Contributor

    OK for me.
    It is only relevent for multi block IOs (fiew at the moment).
    We maybe should think about implementing some king of iter or yield at relationship level.
    For instance Block.segments or Segment.analogsignals.

    But for now iter on Block at Io level is good.

    Thanks.

  2. rproepp commented on Jul 22, 2014

    @rproepp
    Member

    Sounds good and easy to implement. Concerning relationships below blocks, that's what lazy cascading is for: Only objects that are actually accessed are loaded, transparent to the user.

  3. samuelgarcia commented on Jul 22, 2014

    @samuelgarcia
    Contributor

    OK.

  4. added this to the 0.4 milestone on Feb 5, 2015
  5. modified the milestones: , 0.4 on Jul 4, 2016
  6. samuelgarcia commented on Jun 14, 2023

    @samuelgarcia
    Contributor

    Let close now. And reopen if someone want to implement it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions