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 Distribution

csvdir-0.6.0.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

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

csvdir-0.6.0-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file csvdir-0.6.0.tar.gz.

File metadata

  • Download URL: csvdir-0.6.0.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for csvdir-0.6.0.tar.gz
Algorithm Hash digest
SHA256 7980a81dec72e113291707b93a1e5f5b7e7d184624245149052893cc632a9ef9
MD5 a4786d886138e70a470a1636322f2591
BLAKE2b-256 a9b11f6fc28fc18b7e6e936ac125f4b4ec47115f4727bd723799e9dce28fe000

See more details on using hashes here.

File details

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

File metadata

  • Download URL: csvdir-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 17.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for csvdir-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c0d854e59501c785edd8d679f75e1b48aa41e39ed485ea45d53b43f038706109
MD5 d2d90d86b1e4fc772e4550d116a70da3
BLAKE2b-256 8fe68a2a4b45887dd00d641e461e15db4fb5013b98885c99b226eb9e84ee41fc

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