The API of the csv module in Python 2 is drastically different from the csv module in Python 3. This is due, for the most part, to the difference between str in Python 2 and Python 3.
The semantics of Python 3’s version are more useful because they support unicode natively, while Python 2’s csv does not.
Installation
pip install backports.csv
Usage
First make sure you’re starting your file off right:
from backports import csv
Then be careful with your files to handle the encoding. I suggest using io.TextIOWrapper, opening your file in binary mode, and declaring your desired encoding when constructing your TextIOWrapper.
from backports import csv
from io import TextIOWrapper
def read_csv(filename):
with TextIOWrapper(open(filename, 'rb'), encoding='utf-8') as f:
reader = csv.reader(f)
for row in reader:
yield row
def write_csv(filename, rows):
with TextIOWrapper(open(filename, 'wb'), encoding='utf-8') as f:
writer = csv.writer(f)
for row in rows:
writer.writerow(row)
License
This is a port of the csv module in the Python 3 standard libary. Because of this, backports.csv follows the same license as Python, whatever that may be at any given point in time.
1.0.1 (2016-02-11)
Better error messages for invalid dialects. - thanks to @kengruven for the bug report
1.0 (2016-02-11)
Initial Release
Metadata
Release files for backports.csv 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| backports.csv-1.0.1.tar.gz | 11.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| backports.csv-1.0.1-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 23.9 kB
Release files / backports.csv-1.0.1.tar.gz
| Download URL | backports.csv-1.0.1.tar.gz |
|---|---|
| Size | 11.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c148acae78fad395e5b4dbcd01a48af96c4a50b3f5adb71c700a1e45d2e237d9
|
|
BLAKE2b-256 checksum How to use checksums |
f97769c8e7d6aa5ec6f8eeb7f34de7180b745a598526dd79a0d83c89a3413a70
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / backports.csv-1.0.1-py2.py3-none-any.whl
| Download URL | backports.csv-1.0.1-py2.py3-none-any.whl |
|---|---|
| Size | 12.6 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
6d8c18ce7bdab1eb5af13936a719a4db2c8233b8558f96904df92e4ba1fa623b
|
|
BLAKE2b-256 checksum How to use checksums |
9ea0272085e8f11d94bf3b7efc719134c8cdcf5ada4ad251d6c461544381dba7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |