Skip to main content

snips lines from text files (automate creation of student copy from solution)

Project description

snip_copy

snip_copy creates copies of a file, snipping away portions of the original.

Our motivating use-case is to allow instructors to manage only a rubric.py copy of their assignment which contains student instructions, solutions to all problems and, grading criteria to be shared with TAs. Using snip_copy one can quickly create solution.py and student.py versions of the same assignment from rubric.py.

Installation

pip install snip_copy

Quick-start

Consider an example input file input.txt:

this text will be left unmodified in all copies

#! snip: a, b
this text will be removed in copies a and b
#! snip-end

this text will (also) be left unmodified in all copies

Running snip_copy as:

    $ python3 -m snip_copy input.txt

generates two files, a.txt and b.txt where each has removed the snipped section.

Jupyter Notebooks

You can add snip commands to jupyter notebook cells (code or markdown) to achieve similar behavior as well. For example, given input rubric.ipynb, running the following command:

    $ python3 -m snip_copy rubric.ipynb

generates solution.ipynb and student.ipynb.

Notes:

  • a copy is made for each item which appears in a comma separated list after any snip command in the entire document
  • snip commands are removed in all copies created
  • Each snip command line contains #!, which comments out the line, so it may live unobtrusively in python code. You can modify this string to produce similar behavior in another programming language:
    $ python3 -m snip_copy input.txt --cmd '// !'
  • It can be cumbersome to type the full names of every output file with every snip command. Consider using --split:
    $ python3 -m snip_copy hw_rub.txt --split '_'

which will "split" the input file name at the last occurrence of the given string. For example, if hw_rub.txt has the same contents as input.txt at the top, then the terminal command immediately above creates hw_a.txt and hw_b.txt.

  • cells which do not include any snip commands are left unmodified in all copies
  • if a cell's snip command would remove its entire contents, then we remove the cell entirely in the copy generated, rather than give a cell which is empty
  • You can call snip_copy from within jupyter via a code containing:
>>> #! snip: stud, sol
>>> !python3 -m snip_copy hw_rub.ipynb`

which will make copies, removing this cell from each copy.

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

snip_copy-0.0.3.tar.gz (45.8 kB view details)

Uploaded Source

Built Distribution

snip_copy-0.0.3-py3-none-any.whl (33.6 kB view details)

Uploaded Python 3

File details

Details for the file snip_copy-0.0.3.tar.gz.

File metadata

  • Download URL: snip_copy-0.0.3.tar.gz
  • Upload date:
  • Size: 45.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for snip_copy-0.0.3.tar.gz
Algorithm Hash digest
SHA256 bb1af9909080ad131a1ebc8d350f2b1e436a0c71e4b8bb130b55b92b8b9d34c6
MD5 20856a1f83280b04be4ff838f847ec25
BLAKE2b-256 273418a626ba8e0839f874ec8d2370de037fc04e704e5ab7f599bdf98e5d8121

See more details on using hashes here.

File details

Details for the file snip_copy-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: snip_copy-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 33.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for snip_copy-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6808965ce59b7e8634eeaebfcb7810ac37d756a50cc2fee65308e26247fad37c
MD5 36d8dcd6b638049aea03103366f9fa98
BLAKE2b-256 dbea58269013892487900439044cf45969ab09163a92c8e7aa94e60cb6a86167

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page