| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Inspired by Ruby Koans, this is a set of small, ordered exercises that walk you through the Python language one failing test at a time. You learn by fixing the next broken thing.
Targets Python 3.14. No third-party dependencies — just the standard library.
python3.14 contemplate_koans.pyEach run:
For a hands-free loop — edit, save, see the new state — pass --watch:
python3.14 contemplate_koans.py --watchThe screen clears and the koans re-run every time a file under koans/ or runner/ changes. Ctrl-C to stop. Add --interval 0.2 to poll faster.
Every koan is a unittest-style test. Many tests contain a placeholder named __ (double underscore). Your job is to edit the koan file and replace each __ with the value that makes the test pass. Then re-run.
def test_fill_in_values(self):
self.assertEqual(__, 1 + 1) # become: self.assertEqual(2, 1 + 1)A typical session looks like this:
$ python3.14 contemplate_koans.py Thinking About Asserts test_assert_truth has damaged your karma. The Master says: You have not yet reached enlightenment. The answers you seek... False is not true : This should be true — make it so. Please meditate on the following code: In /…/koans/about_asserts.py:17 In AboutAsserts.test_assert_truth mountains are merely mountains your path thus far [X ] 0/361
Open koans/about_asserts.py at line 17, fix it, save, and run again. Repeat until you reach enlightenment.
The koans walk through:
python_koans/
├── contemplate_koans.py # entry point — run this
├── koans/
│ ├── about_*.py # one file per topic; edit these
│ └── path_to_enlightenment.py
└── runner/
├── koan.py # Koan base class + the `__` placeholder
└── sensei.py # walks the path and reports
The koan files under koans/ are the only files you should need to edit. Walk slowly. Read each __ in context. Look up the docs when you need to. The machine is patient; so should you be.
Because the most efficient way to learn a language is to be wrong in small, specific, immediately-corrected ways. The koan structure forces you to confront one idea at a time and to verify your mental model against the interpreter — which is the only authority that matters.
Before enlightenment; chop wood, carry water. After enlightenment; chop wood, carry water.
| Back | FazBrowse Home | New Git URL |