Skip to main content

outputdatareader

This outputdatareader reads the necessary data from a text file output as a result of program execution.

There are many programs that output the results of an execution to a text file, but the output is not always in a consistent format. If the output consists of multiple sections, each of which is formatted differently, it can be difficult for a single analyzer to provide the entire output. Also, there are cases where only some sections are wanted.

With outputodatareader, you do not necessarily need to read the entire output, only the parts you want.

Install

outputdatareader can be installed with pip:

$ pip install outputdatareader

Or add it to your project using the package manager:

$ poetry add outputdatareader

Usage

How it works

outputdatareader consists of two stages

  1. the scanner breaks the text file into appropriate segments (e.g., one line)
  2. the reader repeatedly retrieves segments from the scanner one by one and reads them.

The reader processes the segments retrieved from the scanner one at a time, but can select and read only the ones it really needs. Unnecessary segments can be discarded.

The reader can also delegate part of the processing to another reader. When the processing comes back, it continues from there.

Reader

Define a subclass that extends the outputdatareader.readers.Base class and create an instance for use. This class provides the framework for the read loop, so the subclass can concentrate on parsing and reading segments retrieved from the scanner. The subclass implements the following methods:

  • setup
  • loop
  • teardown

Only loop is required. This method is the essential part of reading. setup and teardown pre-process and post-process the read, respectively.

Several private methods are available during the read loop.

  • _next_loop jumps to “next loop”.
  • _exit_loop exits the reading loop. teardown is executed before returning to the caller.
  • _exit_read skips teardown and finishes reading.
  • _unshift returns one segment to the scanner.

_unshift is needed when the segment received from the scanner is the beginning of the “next section” to be read by another reader. If you return one segment to the scanner and then stop reading, another reader that reads the “next section” can start reading from there.

Scanner

The scanner breaks the text file into appropriate segments and provides them to the reader. The scanner is an iterable object.

To create your own scanner, extend outputdatareader.scanners.Base class and implement the method _scan. _scan is responsible for breaking it down into appropriate segments.

outputdatareader.scanners module provides LineScanner to scan one line at a time, and CsvScanner to scan a CSV file one record at a time.

Example

from outputdatareader.scanners import LineScanner
from outputdatareader.readers import Base


class MainReader(Base):
    def loop(self, line):
        if line.statswith('Section 2'):
            self._unshift()
            reader = Section2Reader(self.scanner, {})
            self.holder['section_2'] = reader.read()
        elif line.statswith('Section 5'):
            self._unshift()
            reader = Section5Reader(self.scanner, {})
            self.holder['section_5'] = reader.read()
        else:
            # ignore other sections
            pass


class Section2Reader(Base):
    def loop(self, line):
        if line.startswith('Section 3'):
            self._exit_read()
        else:
            # implement here


class Section5Reader(Base):
    def loop(self, line):
        # implement here


def main():
    scanner = LineScanner('some_output.txt', encoding='utf-8')
    result_holder = {}
    reader = MainReader(scanner, result_holder)
    result = reader.read()
    print(result)


main()

License

MIT License.

Metadata

Release files for outputdatareader 0.9.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for outputdatareader 0.9.1
File Size Uploaded Provenance Actions
outputdatareader-0.9.1.tar.gz 5.3 kB Without provenance Details for outputdatareader-0.9.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for outputdatareader 0.9.1
File Interpreter ABI Platform Actions
outputdatareader-0.9.1-py3-none-any.whl Python 3 none any Details for outputdatareader-0.9.1-py3-none-any.whl

Total release size: 11.8 kB

Release files / outputdatareader-0.9.1.tar.gz

Download URL outputdatareader-0.9.1.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
6709d86dfaf0d7823c4b6e90d6d8d330f1feee5e204c8846c243fa15b08b75c5
BLAKE2b-256 checksum
How to use checksums
cce825cfff1f90a5a2dac9359011d3ef0a94ea7cbe9199b6ce55c15354d2891f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.5 CPython/3.12.8 Linux/6.8.0-51-generic

Release files / outputdatareader-0.9.1-py3-none-any.whl

Download URL outputdatareader-0.9.1-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
75ba9c7de4c7f3d4a1add85790edef332a3422292c39a6902bb5042747b1e3d7
BLAKE2b-256 checksum
How to use checksums
e0a55e13acf8cf83e9901da1cc411ec49a59e54d8981143c4b7fe78b9af8d727
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.5 CPython/3.12.8 Linux/6.8.0-51-generic

Security for outputdatareader 0.9.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.9.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page