Skip to main content

A Swiss Army knife iterator for files (or any iterator of strings)

Project description

File Iter

License Code style: ruff GitHub Workflow Status Codecov

A Swiss Army knife iterator for files (or any iterator of strings)

  • Strips lines
  • Keeps track of the current line: current_line
  • Keeps track of the line number: position
    • Specify position if entering in the middle of a file: FileIter(f, position=10)
  • Peek at the next line: peek()
  • Jump ahead n lines jump(n)
  • Check if empty: isempty()
  • Filter out unimportant lines:
    • Always filter: FileIter(f, filter_func=is_data)
    • Filter only single next(): filter_next(filter_func)
>>> def is_data(line: str) -> bool:
...    return len(line) > 0 and (line[0] != "#")
>>> my_iter = FileIter(
...     ["Hello", "", "# comment", "World", "How", "are", "you?"],
...     filter_func=is_data
... )
>>> next(my_iter)
'Hello'
>>> my_iter.peek()  # peek does not respect filter_func
''
>>> next(my_iter)  # skips "" and "# comment"
'World'
>>> my_iter.position
3
>>> my_iter.current_line
'World'
>>> my_iter.jump(3)  # jump does not respect filter_func
'you?'
>>> my_iter.position
6
>>> my_iter.isempty()
True
>>> my_iter.peek(default="default")
'default'

Credits

This package was created with Cookiecutter and the jevandezande/poetry-cookiecutter project template.

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

file_iter-0.1.3.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

file_iter-0.1.3-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file file_iter-0.1.3.tar.gz.

File metadata

  • Download URL: file_iter-0.1.3.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.2 Linux/5.15.146.1-microsoft-standard-WSL2

File hashes

Hashes for file_iter-0.1.3.tar.gz
Algorithm Hash digest
SHA256 57d840ff62c774765b09ef3ad563050246d1dfde956cba4510376127fe026bae
MD5 712b6120f9c3573e153577f80dbd2913
BLAKE2b-256 7cd165927e99d65e5a6f30cde93f585cab2bbf6b62efe07396e34d116f1c7f06

See more details on using hashes here.

File details

Details for the file file_iter-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: file_iter-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.2 Linux/5.15.146.1-microsoft-standard-WSL2

File hashes

Hashes for file_iter-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 020e15aec7083f746ab54624ac0f90843073379c51e416ddf8c28abaf4bc81fb
MD5 ea4dd634a1aed76324a14148b0b314ab
BLAKE2b-256 78a5a2d4245e990c089dcd23bbf8ba4cdd7589cdf1743c933d9ccefc92be8515

See more details on using hashes here.

Supported by

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