Skip to main content

Make any iterator a look-ahead iterator. Provides specialized look-ahead iterators for text files.

Project description

lookaheadtools

The lookaheadtools module extends generic iterators to support look-ahead, and also provides some convenient look-ahead iterators that are useful for processing text files.

Lookahead is implemented by extending iterators with support for __getitem__(). For example:

import lookaheadtools as la
looker = la.lookahead(iter([0,1,2,3,4]))
assert looker[3] == 3
assert looker[0] == 0
assert looker[1000] == None
assert looker[0:9:2] == [0,2,4]
assert next(looker) == 0
assert looker[0] == 1

As seen in the example, myLookaheadIter[0] returns the value that will be returned by next(myLookaheadIter) but without consuming it. Arbitrary lookahead distance is supported. Attempts to lookahead past the end of the iterator will return None. The look-ahead index can be any slice with positive indices.

Classes Provided

Lookahead(object) – Convert any iterator into a look-ahead iterator.

LinesOf(object) – Iterate line-by-line over a string, emulating text file iteration.

Lexpos (a named tuple) – Convenience class for capturing lexical tracking information.

FileLookahead(Lookahead) – FileLookahead() is a specialization of the Lookahead() class that iterates by characters over a text file with full lexical position tracking.

LexAhead(FileLookahead) – LexAhead() is a specialization of FileLookahead() that includes some simple tokenizing utilities, stopping short of being a full tokenizer. See tokenizertools for a module that builds a tokenizer on top of LexAhead().

lookaheadtools news

Update history.

15-Sep-2016

1.0 release. Tweaked setup.py to make it more robust.

16-June-2014

0.2b release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lookaheadtools-1.0.tar.gz (8.7 kB view details)

Uploaded Source

File details

Details for the file lookaheadtools-1.0.tar.gz.

File metadata

File hashes

Hashes for lookaheadtools-1.0.tar.gz
Algorithm Hash digest
SHA256 c0103819702b0e45a2a8e1b33f559bbc5d4e6113ae4de1fafc33c462585bf4a0
MD5 7be46b8fa8d41c1d0fb085204363a999
BLAKE2b-256 6dd48bfe7fdee92b43afe8d1d63a9de88ea8e5a493ede69815a91c69b0e26f5d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page