linescan.py

linescan.py is a Python 2.7 and 3.3 library I have been developing on and off since May 2013 with version 1.0 finally released on March 4, 2014.

A short summary of linescan.py, taken from README.md.

Similar to the built-in linecache module but designed exclusively for external text files, linescan.py is a no-fail module designed to aid beginner programmers who need to read data from text files but have trouble setting up open() or translating real numbers to counting numbers.

Features

  • Uses counting numbers to denote line numbers, removing the need to start counting from zero
  • Stores up to ten previous scans for later retrieval, although the number of stored scans can be changed and deliberately cleared
  • Allows specification of file encoding using encoding parameter
  • Returns False upon encountering any errors, Exceptions can be raised by running linescan.showerrors(True)
  • Supports Python 2.7 and 3.3

I have intentionally kept the API simple, further emphasizing its beginner-oriented platform.

import linescan
# Scan a single line using UTF-8 encoding
linescan.scan("MyFile.txt", 12, encoding="UTF-8")

# Scan multiple lines using default encoding
linescan.scan("MyFile.txt", 1, 12)

However, I have also added ways to change the default settings, providing more intermediate or experienced programmers some flexibility. Complete API details are on the wiki.

linescan.py has quite a long history. Early on in the development of PatchIt!, I used the linecache module to read the PiP file containing mod details. However, over the course of development I ran into an error that I could not overcome. I switched to the standard open() function, but I still wanted the simplicity of linecache’s syntax.

In May 2013, I began writing linescan.py, a Python module based on linecache’s syntax and reported functionality (I consulted very little of the source code). I intended it to be a short-term project, but I because busy with other work and never finished it. I did work on it every now and then but it was not always much. Later, in January 2014, I revisited linescan.py, and using knowledge I since gained, I ended up rewriting it with an all new API, code base, and features. I planned on releasing v1.0 that month, but yet again something stopped me, this time college. Finally, this month (yesterday actually), I tagged version 1.0 after I added a new parameter to a configuration function.

linescan.py is in early stages, so future updates (if any, although I do want to add a new function) may have breaking API changes. I also want to post it on PyPi (the Python Package Index) but cannot figure out how to configure the setup script. I cannot really explain the module, so you would need to 1) use it yourself, 2) read the API documentation, or 3) read and run the example scripts. 😉

linescan.py is hosted on GitHub and licensed under The MIT License, meaning you can use it in pretty much everything.

Advertisements

One thought on “linescan.py

Comments are closed.