Skip to content

whardier/spliterator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

spliterator

Split line streams into managable chunks

Usage

Take things.txt as follows.

Thing Name Thing 1
Thing Color Red
Thing Hair Big
Thing Motto I am Number 1!
Thing Name Thing 2
Thing Color Red
Thing Hair Big
Thing Motto Seconds Please!

And lets iterate through each line while adding in start and end events around each individual thing.

>>> import spliterator
>>> for event, line in spliterator.chunk(open('things.txt'), 'Thing Name'):
...   print(event, line)
...
START None
LINE Thing Name Thing 1
LINE Thing Color Red
LINE Thing Hair Big
LINE Thing Motto I am Number 1!
END None
START None
LINE Thing Name Thing 2
LINE Thing Color Red
LINE Thing Hair Big
LINE Thing Motto Seconds Please!
END None

Now we can process specific things properly based on the event variable.

About

Split line streams into managable chunks

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages