Skip to main content

Read all csv files in a directory with one iterator.

Project description

A Python package used to iterate through a directory of csv files and read each row as a dict.

Install

pip install csvdir

Examples

>>> import csvdir

>>> reader = csvdir.read_dir('data/')
>>> reader.names
['people1', 'people2']
>>> reader.paths
['data/people1.csv', 'data/people2.csv']

>>> for row in reader:
...    print(row)
...
{'id': '1', 'name': 'Odos', 'age': '38'},
{'id': '2', 'name': 'Kayla', 'age': '31'},
{'id': '3', 'name': 'Dexter', 'age': 'two'},
{'id': '4', 'name': 'Joe', 'age': '44'},
{'id': '5', 'name': 'James', 'age': '55'},
{'id': '6', 'name': 'Luke', 'age': '0'}

>>> for name, row in reader.with_names():
...    print(name, row)
...
'people1' {'id': '1', 'name': 'Odos', 'age': '38'},
'people1' {'id': '2', 'name': 'Kayla', 'age': '31'},
'people1' {'id': '3', 'name': 'Dexter', 'age': 'two'},
'people2' {'id': '4', 'name': 'Joe', 'age': '44'},
'people2' {'id': '5', 'name': 'James', 'age': '55'},
'people2' {'id': '6', 'name': 'Luke', 'age': '0'}

>>> for path, row in reader.with_paths():
...    print(path, row)
...
'data/people1.csv' {'id': '1', 'name': 'Odos', 'age': '38'},
'data/people1.csv' {'id': '2', 'name': 'Kayla', 'age': '31'},
'data/people1.csv' {'id': '3', 'name': 'Dexter', 'age': 'two'},
'data/people2.csv' {'id': '4', 'name': 'Joe', 'age': '44'},
'data/people2.csv' {'id': '5', 'name': 'James', 'age': '55'},
'data/people2.csv' {'id': '6', 'name': 'Luke', 'age': '0'}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

csvdir-0.3.0-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file csvdir-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: csvdir-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.0

File hashes

Hashes for csvdir-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ea70e285918f3a7c537633932b0f75135b34ae86a21899435696b3cac832e306
MD5 f56041c2841d8fbd3bfcba656dd850bc
BLAKE2b-256 dad7e670b4855bca1d422a81e008832605f66fb634a4d2953a08947f06f84884

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