https://github.com/emmsthefemms/csv-reader
csv file reader for python
https://github.com/emmsthefemms/csv-reader
csv pip pypi python
Last synced: 4 days ago
JSON representation
csv file reader for python
- Host: GitHub
- URL: https://github.com/emmsthefemms/csv-reader
- Owner: emmsthefemms
- License: apache-2.0
- Created: 2020-08-13T08:01:45.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-09-04T09:07:02.000Z (almost 6 years ago)
- Last Synced: 2026-01-07T11:50:34.098Z (6 months ago)
- Topics: csv, pip, pypi, python
- Language: Python
- Homepage:
- Size: 5.67 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Introduction
Welcome to my small python project.
This library just provides some functions to read from csv files.
I developed this library for fun.
If anyone wants to contribute, feel free to contact me or open an issue.
This library uses the built-in `csv` module
## Installation
Type this into your command prompt:
`pip install csv-reader`
## Usage
at the top of your py files:
```python
from csv_reader import Reader
```
in your code:
```python
with Reader.openWithName("test.csv") as file:
for line in file:
print(line)
```
## Documentation
Visit https://csv-reader.readthedocs.io/en/latest for the documentation.
## Examples
The examples can also be found at https://csv-reader.readthedocs.io/en/latest/Examples.html
### Reader
#### openWithName()
```python
with Reader.openWithName("test.csv") as file:
for line in file:
print(line)
```
note: when used in a `for` loop, each `line` is a list of values in each line of the file.
#### openWithFile()
``` python
with Reader.openWithFile(open("test.csv" newline="")) as file:
for line in file:
print(line)
```
note: when used in a `for` loop, each `line` is a list of values in each line of the file.
#### readFromName()
```python
with Reader.readFromName("test.csv") as file:
for line in file:
print(line)
```
note: `line` is a string.
#### readFromFile()
```python
with Reader.readFromFile(open("test.csv", newline="")) as file:
for line in file:
print(line)
```
note: `line` is a string.
### Writer
The Writer module provides 2 classes for writing to csv files. 1 uses lists while another uses dicts.
```python
from csv_reader import Writer
```
#### csv_reader.CSVWriter
```python
with CSVWriter("test.csv") as file:
file.write(["test1", "test2"])
```
#### csv_reader.CSVDictWriter
```python
with CSVDictWriter("test.csv", ["field1", "field2"]) as file:
file.writeRows([
{"field1":"test1", "field2":"test2"},
{"field1": "test3", "field2": "test4"}
])
```