CSV-like¶
Read CSV-like files with support of comments and trimming in native python.
License¶
Copyright 2021 MikeSmithEU
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Installation¶
CSV-like requires Python version 3.5 or above.
From PyPI (preferred)¶
This is the easiest and preferred way of installing csvlike
.
Install Python 3.5 or above (latest stable version for your OS is preferred):
Use the guides available at The Hitchhiker’s Guide to Python
Install the package using
pip
, this will also install all requirements:python3 -m pip install csvlike
Test and use
CSV-like should now be installed and usable.
See Usage for more information on how to use.
From the repository¶
For building the documentation locally and working with a development copy see Development
Usage¶
TODO
Development¶
Setting up environment¶
This assumes git
and Python
3.5 or above are already installed on your system (see Installation).
Fork the repository source code from github to your own account.
Clone the repository from github to your local development environment (replace
[YOURUSERNAME]
with your github username):git clone https://github.com/[YOURUSERNAME]/csvlike.git cd csvlike
Create and activate a local environment:
python3 -m pip install venv python3 -m venv source bin/activate
Install the package, this will also install all requirements. This does an "editable" install, i.e. it creates a symbolic link to the source code:
make dev
You now have a local development environment where you can commit and push to your own forked repository. It is recommended to run the tests to check your local copy passes all unit tests:
make test
Warning
The development version of csvlike is only available in your current venv environment. Make sure to run source bin/activate
to activate your local venv before using csvlike.
Building the documentation¶
First install the dependencies for building the documentation (sphinx, etc.) using:
make setupdocs
This only needs to be done once.
Then to build the documentation locally:
make docs
The documentation will be created in /docs/build/html/
csvlike package¶
Submodules¶
csvlike.csv module¶
Module providing a custom CSV file parser with support for whitespace trimming, empty lines filtering and comment lines
-
exception
csvlike.csv.
CSVParserError
(message, line, char, index)[source]¶ Bases:
ValueError
Some error occured while attempting to parse the file
-
class
csvlike.csv.
DefaultDialect
[source]¶ Bases:
csvlike.csv.Dialect
Default csv-like dialect, using comma separators, double quote chars and hash as the comment char with newline and tab char trimming.
-
commentchar
= '#'¶
-
delimiter
= ','¶
-
ignoreemptylines
= True¶
-
quotechar
= '"'¶
-
trimleft
= ' \t\n\r'¶
-
trimright
= ' \t\n\r'¶
-
-
class
csvlike.csv.
Dialect
[source]¶ Bases:
object
Abstract base class for Dialect
-
commentchar
= None¶
-
delimiter
= None¶
-
quotechar
= None¶
-
trimleft
= None¶
-
trimright
= None¶
-
-
exception
csvlike.csv.
InvalidDialectError
[source]¶ Bases:
ValueError
An invalid dialect was supplied
-
class
csvlike.csv.
Reader
(file: TextIO, dialect: csvlike.csv.Dialect, debug=None)[source]¶ Bases:
object
CSV-like file reader with support for comment chars, ignoring empty lines and whitespace trimming on both sides of each field.
-
exception
csvlike.csv.
UnallowedQuoteError
(message, line, char, index)[source]¶ Bases:
csvlike.csv.CSVParserError
A quote is not allowed there
-
exception
csvlike.csv.
UnclosedQuoteError
(message, line, char, index)[source]¶ Bases:
csvlike.csv.CSVParserError
A quote wasn't properly closed
-
exception
csvlike.csv.
UnknownDialectError
[source]¶ Bases:
ValueError
An unknown dialect was requested
-
class
csvlike.csv.
WhitespaceDialect
[source]¶ Bases:
csvlike.csv.DefaultDialect
Same as default Dialect, but with spaces also trimmed.
-
delimiter
= ' \t'¶
-
-
csvlike.csv.
reader
(file: TextIO, dialect: Union[None, str, csvlike.csv.Dialect] = None, **kwargs) → csvlike.csv.Reader[source]¶
Module contents¶
Package benchmarkstt