Skip to main content

Simple IO eliminating the boilerplate.

Reason this release was yanked:

Invalid documentation in the README

Project description

CleanIO is a simple project illustrating how to use the yield statement to make reading and writing text files simple and to remove the clutter and boilerplate from your mainstream code.

Usage

Read a Text File

To read a text file.

  1. Add an import statement

    from CleanIO import CleanRead

  2. Create an instance of the CleanRead class and pass it the desired filename or path

    cr = CleanRead(<<file name or path>>)

  3. Accept each line of the file from the generator (e.g. with a for statement) from the clean_read method

    for line in cr.clean_read():

  4. When the generator finishes, it will return a StopIteration exception (which the for statement will handle automatically

The file is opened, read, and closed automatically with no extra boilerplate needed.

Write a Text File

To write a text file:

  1. Add an import statement.

    from CleanIO import CleanWrite

  2. Create an instance of the CleanWrite class and pass it the desired filename or path.

    cw = CleanWrite(<<file name or path>>)

  3. Send each line of the file to the generator via the clean_writeline method

    cw.clean_writeline(<<line>>)

  4. When done, notify the generator

    cw.clean_close()

The file is opened, written, and closed automatically with no extra boilerplate needed.

Comments

  • Read or write as many files as you need.

  • This has not been tested with async calls.

  • This code has been formatted with the blue library.

Structure

CleanIO consists of two classes, one for reading a text file and one for writing a text file.

Each class uses the yield statement for maintaining the position of the file and its place in the method. Other “boilerplate” code, such as the open, starting the generator, and closing is handled automatically in the class.

Possible Future Enhancements

There are several possible enhancement to this module that come to mind.

Currently this module is designed to read and write text files. It could be enhanced to also read and write binary files.

Currently the CleanWrite class assumes it will be getting one line at a time (without the newline or ‘\n’ at the end). It could be enhanced to output partial lines or multiple lines at a time if the user desires to put the line endings on themselves.

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

cleanio-0.1.3.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

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

cleanio-0.1.3-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cleanio-0.1.3.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.5 Linux/6.10.5-1-MANJARO

File hashes

Hashes for cleanio-0.1.3.tar.gz
Algorithm Hash digest
SHA256 2a2b29016aecc951f1c3c54f9f0c05fe0a31e00b5acf48066d38dd9b1526569c
MD5 1c596daa5b6693901c563cb63f103888
BLAKE2b-256 e85d29d37c243cbe2ce773140a8c5f831c6e034e6b0f5fd264dbcc605b2aa177

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cleanio-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.5 Linux/6.10.5-1-MANJARO

File hashes

Hashes for cleanio-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e4128ea467def85eec0cf22413a672420d3267ca345b4aef46f130b9ba5fe3d8
MD5 45c9b38eec9ad971be0cd0c19fa2666d
BLAKE2b-256 df2a21e4583d5f6766e12758f6b238cc26d270749810c243c711510a9c133deb

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