Skip to main content

cssresumable

Adding tiny resume function for your csv reading iterator.

examples

00main.py

import sys
import os
import random
from io import StringIO
from csvresumable import DictReader

data = """\
id,name
1,foo
2,bar
3,boo
"""

random.seed(int(os.environ.get("SEED", "0")))
for row in DictReader(StringIO(data)):
    n = random.random()
    if n < 0.5:
        print("fail {}".format(n), file=sys.stderr)
        sys.exit(0)
    print("\t", row["name"])
print("finished")

resuming until success.

SEED=0 python 00main.py
fail 0.420571580830845
	 foo
	 bar
SEED=1 RESUME=1 python 00main.py
fail 0.13436424411240122
SEED=2 RESUME=1 python 00main.py
	 boo
finished
SEED=5 python 00main.py
	 foo
	 bar
	 boo
finished

or setting with resume option (run this script, such as python 01main.py --resume)

--- 00main.py	2018-06-16 04:19:51.573578443 +0900
+++ 01main.py	2018-06-16 04:20:04.760554103 +0900
@@ -4,17 +4,23 @@
 from io import StringIO
 from csvresumable import DictReader

-data = """\
+data = """
 id,name
 1,foo
 2,bar
 3,boo
 """

+import argparse
+parser = argparse.ArgumentParser()
+parser.add_argument("--seed", default=0, type=int)
+parser.add_argument("--resume", action="store_true")
+args = parser.parse_args()
+
 random.seed(int(os.environ.get("SEED", "0")))
-for row in DictReader(StringIO(data)):
+for row in DictReader(StringIO(data), resume=args.resume):
     n = random.random()
-    if n < 0.5:
+    if n > 0.8:
         print("fail {}".format(n), file=sys.stderr)
         sys.exit(0)
     print("\t", row["name"])

with multi files

from csvresumable import DictReader

files = ["a.csv", "b.csv"]
for f in files:
    r = DictReader(f)
    for row in r:
        do_something(row)

more

Metadata

Release files for csvresumable 0.0.3.post2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for csvresumable 0.0.3.post2
File Size Uploaded Provenance Actions
csvresumable-0.0.3.post2.tar.gz 4.8 kB Without provenance Details for csvresumable-0.0.3.post2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for csvresumable 0.0.3.post2
File Interpreter ABI Platform Actions
csvresumable-0.0.3.post2-py2.py3-none-any.whl Python 2, Python 3 none any Details for csvresumable-0.0.3.post2-py2.py3-none-any.whl

Total release size: 11.2 kB

Release files / csvresumable-0.0.3.post2.tar.gz

Download URL csvresumable-0.0.3.post2.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
0840b7bc6ef4161c39572c8366d8265375da60406f38d59f3d17aaecbc7ffc58
BLAKE2b-256 checksum
How to use checksums
8d771f45e9b653596f2f1adfc4b9c5a36951a7a45fb66e3e636169de335fc31f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / csvresumable-0.0.3.post2-py2.py3-none-any.whl

Download URL csvresumable-0.0.3.post2-py2.py3-none-any.whl
Size 6.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
dbe58d8079d96ee07c985f67db91e57148cf1d01c2503cf410cbfe62a5c217d4
BLAKE2b-256 checksum
How to use checksums
28edf9bf4ff693ce4c9233ede0bf57450d60674d4b152b2298405627888ae748
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for csvresumable 0.0.3.post2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page