python crossword puzzle library
Project description
Implementation of .puz crossword puzzle file parser based on .puz file format documentation here: http://code.google.com/p/puz/wiki/FileFormat
Examples
Load a puzzle file:
import puz p = puz.read('testfiles/washpost.puz')
Print clues with answers:
numbering = p.clue_numbering() print 'Across' for clue in numbering.across: answer = ''.join( p.solution[clue['cell'] + i] for i in range(clue['len'])) print clue['num'], clue['clue'], '-', answer print 'Down' for clue in numbering.down: answer = ''.join( p.solution[clue['cell'] + i * numbering.width] for i in range(clue['len'])) print clue['num'], clue['clue'], '-', answer
Print the grid:
for row in range(p.height): cell = row * p.width # Substitute p.solution for p.fill to print the answers print ' '.join(p.fill[cell:cell + p.width])
Unlock a scrambled solution:
p.unlock_solution(7844) # p.solution is unscambled
Save a puzzle with modifications:
p.fill = 'LAMB' + p.fill[4:] p.save('mine.puz')
Notes
The parser is as strict as Across Lite, enforcing internal checksums and magic strings. The parser is designed to round-trip all data in the file, even fields whose utility is unknown. This makes testing easier. It is resilient to garbage at the beginning and end of the file (for example some publishers put the filename on the first line and some files have a rn at the end).
In addition to the handful of tests checked in here, the library has been tested on over 9700 crossword puzzles in .puz format drawn from the archives of several publications including The New York Times, The Washington Post, The Onion, and, the Wall Street Journal. As of writing, it can round-trip 100% of them with full fidelity.
Running tests
python tests.py
License
MIT License.
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
Built Distribution
File details
Details for the file puzpy-0.2.6.tar.gz
.
File metadata
- Download URL: puzpy-0.2.6.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7809144e07691da44598001090805d99eb1bcf8475908a23638a4061605c4015 |
|
MD5 | 547aa55d1873628c12ea2697560ef376 |
|
BLAKE2b-256 | 5ee28186d481b80bd58127ada1f61da4e6c2af25ee6fe59ae0f709df24492e21 |
File details
Details for the file puzpy-0.2.6-py2.py3-none-any.whl
.
File metadata
- Download URL: puzpy-0.2.6-py2.py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90faa0e8b5497ed51b57e15911d66351a6bad9665c7a01218c6acd747a9dcd32 |
|
MD5 | ac002361265b35cec304f17caa7e2fa4 |
|
BLAKE2b-256 | 29fef31d2bd2de7e74a6826e9f008ca003d00686fd120c3b4c78d23ec3fc87c2 |