Repository navigation
Expand file tree
/
Copy pathdocs.html
More file actions
690 lines (633 loc) · 35.1 KB
/
Copy pathdocs.html
File metadata and controls
690 lines (633 loc) · 35.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Documentation — Python v2</title>
<meta name="description" content="Install Python v2 in VS Code, dev containers, Codespaces, desktop terminals, or any code editor. Full language reference included.">
<link rel="icon" type="image/svg+xml" href="favicon-v2.svg">
<link rel="stylesheet" href="style.css">
</head>
<body>
<a class="skip-link" href="#main-content">Skip to content</a>
<!-- ============ top utility bar ============ -->
<div class="topbar">
<nav class="topbar-inner" aria-label="Site">
<a href="index.html">Python</a>
<a href="index.html#community">PSF</a>
<a class="active" href="docs.html">Docs</a>
<a href="download.html">PyPI</a>
<a href="games.html">Games</a>
<a href="index.html#community">Community</a>
<a href="playground.html">Playground</a></nav>
</div>
<!-- ============ masthead ============ -->
<header class="masthead">
<div class="masthead-inner">
<a class="brand" href="index.html">
<img src="logo-v2.svg" alt="Python v2 logo — two snakes, red and blue" width="64" height="64">
<span class="brand-word">python<sup>™</sup><em>v2</em></span>
</a>
<div class="masthead-tools">
<a class="btn-youtube" href="https://www.youtube.com/@CubeCometYT" target="_blank" rel="noopener">▶ Subscribe</a>
<form class="searchbox" id="search-form" role="search">
<span class="search-mag" aria-hidden="true">⌕</span>
<label class="sr-only" for="search-input">Search</label>
<input type="search" id="search-input" placeholder="Search">
<button type="submit" class="btn-go">GO</button>
</form>
<button class="btn-social" id="social-btn" type="button">Socialize</button>
</div>
</div>
</header>
<!-- ============ main nav ============ -->
<nav class="mainnav" aria-label="Main">
<div class="mainnav-inner">
<a href="index.html#about">About</a>
<a href="download.html">Downloads</a>
<a href="docs.html">Documentation</a>
<a href="tutorial.html">Tutorial</a>
<a href="games.html">Games</a>
<a href="guide.html">50 Guides</a>
<a href="index.html#community">Community</a>
<a href="playground.html">Playground</a></div>
</nav>
<!-- ============ page head ============ -->
<section class="page-head">
<div class="page-head-inner">
<h1>Documentation</h1>
<p>Everything you need to get Python v2 running: on your desktop, in
VS Code, in a dev container or Codespaces, or in any code editor you
already love. Then the whole language and PyHope game engine, on one page.
Want more? Read the <a class="hero-link" href="guide.html">50-topic field guide</a>.
New to Python v2? <a class="hero-link" href="tutorial.html">Start the
tutorial</a> — or <a class="hero-link" href="playground.html">open the
dual-runtime Playground</a> for commands, errors, and website templates.</p>
</div>
</section>
<main id="main-content" class="doc-section">
<div class="doc-section-inner">
<!-- ==================== INSTALL ==================== -->
<h2 id="install"><span class="badge">01</span> Install — Desktop</h2>
<p>Python v2 has <strong>no dependencies</strong> and <strong>no install step</strong>.
If you have Python 3.10+ and Git, you're done. Works on macOS, Linux,
Windows (native or WSL), and a fridge with a shell.</p>
<div class="steps">
<strong>Step 1 — check Python</strong>
<pre class="terminal"><code>python3 --version # need 3.10 or newer
git --version</code></pre>
</div>
<div class="steps">
<strong>Step 2 — get the runtime</strong>
<pre class="terminal"><code>git clone https://github.com/gefrus112/pythonv2
cd pythonv2</code></pre>
</div>
<div class="steps">
<strong>Step 3 — verify it works</strong>
<pre class="terminal"><code>python3 -m pyv2 --version
# Python v2 1.1.0
python3 -m pyv2 examples/hello.pyv2
# Hello, World!
# 2 + 2 = 4</code></pre>
</div>
<div class="steps">
<strong>Step 4 — run the test suite (optional, 1 second)</strong>
<pre class="terminal"><code>python3 -m unittest discover -s tests -t .
# ... OK</code></pre>
</div>
<h3>Command line</h3>
<table class="ref-table">
<thead><tr><th>Command</th><th>What it does</th></tr></thead>
<tbody>
<tr><td><code>python3 -m pyv2 script.pyv2</code></td><td>Run a program</td></tr>
<tr><td><code>python3 -m pyv2 -c 'print(42)'</code></td><td>Run a one-liner</td></tr>
<tr><td><code>python3 -m pyv2</code></td><td>Start the REPL (<code>...</code> continues blocks)</td></tr>
<tr><td><code>python3 -m pyv2 --version</code></td><td>Print the version</td></tr>
<tr><td><code>python3 -m pyv2 --help</code></td><td>Show usage</td></tr>
</tbody>
</table>
<h3>Windows notes</h3>
<ul>
<li>If <code>python3</code> is not found, try <code>py -m pyv2 script.pyv2</code>.</li>
<li>WSL is the smoothest path: install Ubuntu from the Microsoft Store,
then follow the three steps above.</li>
</ul>
<!-- ==================== VSCODE ==================== -->
<h2 id="vscode"><span class="badge">02</span> VS Code</h2>
<p>The repository ships ready-made VS Code config in <code>.vscode/</code>
and a language extension in <code>editors/vscode/</code> for
syntax highlighting of <code>.pyv2</code> files.</p>
<h3>Quick start (run & debug your code)</h3>
<div class="steps">
<ol>
<li>Open the <code>pythonv2</code> folder in VS Code
(<strong>File → Open Folder…</strong>).</li>
<li>Open any <code>.pyv2</code> file, e.g. <code>examples/fib.pyv2</code>.</li>
<li>Press <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>B</kbd>
(macOS: <kbd>Cmd</kbd>+<kbd>Shift</kbd>+<kbd>B</kbd>) — the default build task
runs <code>python3 -m pyv2</code> on the current file.</li>
<li>Output appears in the Terminal panel. That's it.</li>
</ol>
</div>
<p>The included <code>.vscode/tasks.json</code> defines two tasks:
<strong>Run Python v2 file</strong> (default build) and
<strong>Python v2 REPL</strong>. The included
<code>.vscode/settings.json</code> associates <code>*.pyv2</code> with
the <code>pyv2</code> language.</p>
<h3>Syntax highlighting (the bundled extension)</h3>
<div class="steps">
<ol>
<li>Copy the extension folder into your VS Code extensions directory:
<pre class="terminal"><code># macOS / Linux
cp -r editors/vscode ~/.vscode/extensions/pyv2-0.1.0
# Windows (PowerShell)
Copy-Item -Recurse editors/vscode "$env:USERPROFILE\.vscode\extensions\pyv2-0.1.0"</code></pre>
</li>
<li>Restart VS Code (or run <strong>Developer: Reload Window</strong>).</li>
<li>Open any <code>.pyv2</code> file — keywords, strings, f-strings,
numbers and comments are now colored.</li>
</ol>
</div>
<p>Prefer the marketplace workflow? Pack it once with the
<code>vsce</code> tool and install the VSIX:</p>
<pre class="terminal"><code>cd editors/vscode
npx @vscode/vsce package # builds pyv2-0.1.0.vsix
code --install-extension pyv2-0.1.0.vsix</code></pre>
<h3>Alternative: Code Runner</h3>
<p>If you use the popular <strong>Code Runner</strong> extension, add this to
your user <code>settings.json</code> and press
<kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>N</kbd> to run:</p>
<pre class="terminal"><code>{
"code-runner.executorMap": {
"python": "python3 -m pyv2"
},
"code-runner.fileDirectoryAsCwd": true
}</code></pre>
<!-- ==================== DEV CONTAINERS ==================== -->
<h2 id="devcontainer"><span class="badge">03</span> Dev Containers & GitHub Codespaces</h2>
<p>Opening the repo in a <strong>dev container</strong> (VS Code or
Codespaces) gives you a ready environment in seconds — Python preinstalled,
tasks wired, tests passing. The config lives in
<code>.devcontainer/devcontainer.json</code> (that's the ".dev" part).</p>
<h3>VS Code Dev Containers</h3>
<div class="steps">
<ol>
<li>Install <strong>Docker</strong> and the
<strong>Dev Containers</strong> extension
(<code>ms-vscode-remote.remote-containers</code>).</li>
<li>Open the repo folder, then run
<strong>Dev Containers: Reopen in Container</strong>
from the Command Palette
(<kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd>).</li>
<li>First boot pulls the Python image; after that everything is instant.</li>
<li>Run <code>python3 -m pyv2 examples/hello.pyv2</code> — or just hit
<kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>B</kbd>.</li>
</ol>
</div>
<h3>GitHub Codespaces</h3>
<div class="steps">
<ol>
<li>On GitHub, open the repo → <strong>Code</strong> →
<strong>Codespaces</strong> → <strong>Create codespace on main</strong>.</li>
<li>VS Code opens in your browser with the dev container already built.</li>
<li>Everything from the desktop guide works identically inside it.</li>
</ol>
</div>
<p>The container runs <code>python3 -m unittest discover -s tests -t .</code>
at build time, so you always start from a green suite.</p>
<!-- ==================== ANY EDITOR ==================== -->
<h2 id="any-editor"><span class="badge">04</span> Any Other Code Editor</h2>
<p>Python v2 is just text plus a CLI. Any editor that can run a shell
command can run it. The universal recipe:</p>
<ul class="checklist">
<li><strong>Coloring</strong> — associate <code>*.pyv2</code> with Python
syntax. It's close enough (and free).</li>
<li><strong>Running</strong> — bind a build/run command to
<code>python3 -m pyv2 "$file"</code> with the working directory set to
your project.</li>
<li><strong>Formatting</strong> — 4 spaces, one statement per line, blocks
end with <code>end</code>. Your formatter can't break it. That's the point.</li>
</ul>
<h3>Sublime Text</h3>
<pre class="terminal"><code>Tools → Build System → New Build System…
{
"cmd": ["python3", "-m", "pyv2", "$file"],
"selector": "source.python",
"working_dir": "$file_path"
}</code></pre>
<h3>Vim / Neovim</h3>
<pre class="terminal"><code>" in init.vim / .vimrc
autocmd BufNewFile,BufRead *.pyv2 set filetype=python
autocmd FileType python nnoremap <F5> :w<CR>:!
\python3 -m pyv2 %<CR></code></pre>
<h3>JetBrains (PyCharm, IntelliJ)</h3>
<ol>
<li><strong>Settings → Editor → File Types</strong> → add
<code>*.pyv2</code> to the <strong>Python</strong> type.</li>
<li><strong>Settings → Tools → External Tools</strong> → add a tool with
program <code>python3</code>, arguments
<code>-m pyv2 $FileName$</code>, working directory
<code>$FileDir$</code>.</li>
<li>Bind it to a shortcut under
<strong>Settings → Keymap</strong>.</li>
</ol>
<h3>Notepad++</h3>
<p><strong>Run → Run…</strong> (F5) with:</p>
<pre class="terminal"><code>cmd /c python3 -m pyv2 "$(FULL_CURRENT_PATH)"</code></pre>
<!-- ==================== PLAYGROUND ==================== -->
<h2 id="playground"><span class="badge">05</span> Browser Playground</h2>
<p><a href="playground.html">Open the Playground</a> to edit and run code
without installing anything. It has line numbers, starter programs,
keyboard execution, command history, and separate Output and Problems
terminals so runtime errors never get mixed into normal program output.</p>
<table class="ref-table">
<thead><tr><th>Mode</th><th>What runs</th><th>Use it for</th></tr></thead>
<tbody>
<tr><td>Python v2</td><td>The complete <code>pyv2.js</code> browser runtime</td><td>Language programs, game data, and website templates</td></tr>
<tr><td>Classic Python</td><td>A documented compatibility subset translated locally to Python v2</td><td><code>def</code>, indentation, variables, loops, lists, maps, functions, and print</td></tr>
<tr><td>Local CPython</td><td>Not embedded in the static website</td><td>Imports, packages, native extensions, files, and the full standard library</td></tr>
</tbody>
</table>
<div class="steps">
<strong>Run code and commands</strong>
<ol>
<li>Choose Python v2 or Classic compatibility.</li>
<li>Pick a starter, edit the source, and press <kbd>Ctrl</kbd>+<kbd>Enter</kbd>.</li>
<li>Read normal text in <strong>Output</strong> and failures in <strong>Problems</strong>.</li>
<li>Use the bottom prompt for expressions and assignments. Commands
<code>:help</code>, <code>:clear</code>, <code>:reset</code>, and
<code>:mode classic</code> are built in.</li>
</ol>
</div>
<p>The Portfolio Starter uses editable Python v2 maps and lists for your
profile, role, biography, skills, statistics, projects, games, location,
and contact details. Valid edits live-sync into a responsive preview.
Switch to <strong>HTML Code</strong> to inspect or copy the exact generated
document, then download it as a standalone page. The desktop New Project
tool creates the richer multi-file offline version.</p>
<!-- ==================== LAUNCHER ==================== -->
<h2 id="launcher"><span class="badge">06</span> Python v2 + PyHope Workspace</h2>
<p>Python v2 1.1 ships with its own desktop workspace. It is implemented
with Python's standard-library <code>tkinter</code> toolkit—no Electron,
pygame, browser shell, subscription, or account.</p>
<h3>Open the app</h3>
<div class="steps">
<pre class="terminal"><code># after running install.bat or install.sh, either command opens the workspace:
pyhope-studio
pyv2-launcher
# the PyHope CLI can launch it too:
pyhope --studio
# always works, even if the command folder is not on PATH:
python3 -m pyv2.launcher</code></pre>
<p>Windows also gets a Desktop shortcut. macOS gets
<code>~/Applications/Python v2 Sudbury.app</code>. Linux gets an app
menu entry. If your Linux distribution separates tkinter, install its
<code>python3-tk</code> package; the language CLI still works without it.</p>
</div>
<h3>App layout</h3>
<table class="ref-table">
<thead><tr><th>Area</th><th>What it does</th></tr></thead>
<tbody>
<tr><td>Home</td><td>Workspace overview and shortcuts to every main tool</td></tr>
<tr><td>Code Studio</td><td>Open, edit, save, and run <code>.pyv2</code>; output/errors stay in the app</td></tr>
<tr><td>Files</td><td>Safe local workspace service: create, read, atomically save, rename, and delete files without path traversal</td></tr>
<tr><td>New Project</td><td>Create Website, Windows app, CLI app, or Game starters without overwriting files</td></tr>
<tr><td>Assets</td><td>Browse and export eight packaged original CC0 PyHope SVGs offline</td></tr>
<tr><td>Games & GPU</td><td>Open the 10-game arcade, animated sprites, and 9M GPU Lab</td></tr>
<tr><td>Connected Editors</td><td>Detect VS Code, VSCodium, Zed, Sublime Text, and PyCharm from PATH; no account or token</td></tr>
<tr><td>Settings</td><td>Workspace folder, preferred editor, code font size, and run autosave</td></tr>
<tr><td>Docs & Learn</td><td>Playground, tutorial, 50-topic guide, reference, and CubeCometYT milestone</td></tr>
<tr><td>Donation</td><td><strong>Coming soon</strong>—the app does not collect money or payment data</td></tr>
</tbody>
</table>
<h3>Build a website with Python v2</h3>
<ol class="checklist">
<li>Open <strong>New Project</strong> and choose <strong>Website</strong>.</li>
<li>The Launcher creates <code>app.pyv2</code>, <code>index.html</code>,
<code>runner.js</code>, an offline copy of <code>pyv2.js</code>, and
ready-to-run <code>.vscode</code> tasks/settings.</li>
<li>Edit <code>app.pyv2</code>. Its structured output fills the profile,
skills, project cards, featured games, and contact section.</li>
<li>Choose local preview. The Launcher starts a safe local HTTP server
on an available port and opens your responsive portfolio.</li>
</ol>
<pre class="terminal"><code># app.pyv2 — one record becomes one part of the page
profile = {name: "Alex", role: "Creative developer"}
skills = ["Python v2", "PyHope", "Web design"]
print("PROFILE|" + profile.name + "|" + profile.role + "|I build playful tools.")
print("ABOUT|My personal biography goes here.")
for skill in skills:
print("SKILL|" + skill)
end
print("GAME|Comet Circuit|Racing|Three-lap AI racing.|games.html#comet-circuit")</code></pre>
<!-- ==================== WINDOWS APPS ==================== -->
<h2 id="windows-apps"><span class="badge">07</span> Production Apps & Windows EXE Builder</h2>
<p>Sudbury Build Tools turn a <code>.pyv2</code> program into a validated,
inspectable application project and—when the native build runs on
Windows—a real one-file <code>.exe</code>. Python v2 does not rename a
Linux or macOS binary and pretend it is a Windows executable.</p>
<h3>Create, run, check, and build</h3>
<pre class="terminal"><code># Complete console application with JSON persistence
pyv2 new windows-app "Comet Tasks"
# Or create a dialog-based app with no terminal window
pyv2 new windows-app "Hello Window" --windowed
pyv2 Comet-Tasks/main.pyv2 --add "Ship the EXE"
pyv2 check Comet-Tasks
pyv2 build Comet-Tasks
# Run this final command on Windows with PyInstaller installed.
# The generated build-windows.bat handles that installation for you.
pyv2 build Comet-Tasks --native</code></pre>
<table class="ref-table">
<thead><tr><th>Generated file</th><th>Purpose</th></tr></thead>
<tbody>
<tr><td><code>main.pyv2</code></td><td>Readable application source using arguments, strict JSON, and persistent app data</td></tr>
<tr><td><code>pyv2app.json</code></td><td>Name, stable app ID, version, publisher, console/windowed mode, icon, and assets</td></tr>
<tr><td><code>build-windows.bat</code></td><td>Validates and builds the real EXE on Windows without administrator access</td></tr>
<tr><td><code>.github/workflows/windows-exe.yml</code></td><td>Optional Windows CI build and downloadable executable artifact</td></tr>
<tr><td><code>build/windows/manifest.json</code></td><td>SHA-256 source and build-input integrity record</td></tr>
<tr><td><code>runtime/pyv2</code></td><td>Exact vendored language runtime used for the build—no moving runtime dependency</td></tr>
<tr><td><code>app.spec</code> + <code>launcher.py</code></td><td>Reviewable PyInstaller recipe and embedded Python v2 host</td></tr>
</tbody>
</table>
<h3>Application APIs</h3>
<pre class="terminal"><code>info = app_info() # name, version, platform, safe data directory
commands = args() # values after the .pyv2 filename / EXE
settings = {theme: "night", zoom: 1.25}
write_text("settings.json", json_encode(settings))
loaded = json_decode(read_text("settings.json"))
print(loaded.theme)
# Other safe services:
# append_text, file_exists, list_dir, make_dir, delete_file
# read_asset, asset_exists, sleep_ms, ui_message, ui_ask</code></pre>
<p>During development, writable data stays in <code>.pyv2-data/</code>
beside the program. Packaged apps use
<code>%LOCALAPPDATA%\PythonV2Apps\APP-ID</code>. Paths are relative and
sandboxed; atomic writes, UTF-8 validation, an 8 MB text limit, asset
size validation, symlink-escape checks, and unmanaged-build-directory
protection are enabled by default.</p>
<div class="callout"><strong>Building from macOS or Linux:</strong>
<code>pyv2 build</code> still creates the complete Windows kit. Copy it
to Windows and run <code>build.bat</code>, or push the generated project
and run its GitHub Actions workflow on a Windows runner. PyInstaller
cannot cross-compile Windows PE files from another operating system.</div>
<p><strong>Signing note:</strong> generated executables are reproducible but
not Authenticode-signed automatically. Public distributors should add
their own protected code-signing certificate in Windows CI; never commit
a certificate or password to the project.</p>
<!-- ==================== PYHOPE ==================== -->
<h2 id="pyhope"><span class="badge">08</span> PyHope Game Engine</h2>
<p>PyHope is Python v2's own dependency-free game engine. It is not
pygame and it installs no native libraries. The portable Python module
handles game logic and terminal previews; the website adds Canvas and
WebGL2 renderers for full visual games.</p>
<h3>Install and verify</h3>
<div class="steps">
<pre class="terminal"><code># one-click: download install.bat (Windows) or install.sh (macOS/Linux)
# manual, from the cloned repo:
python3 -m pip install --user .
pyv2 --version
pyhope --check
pyhope --demo</code></pre>
<p><a href="download.html#pyhope">Download the installers</a>. The
installer adds both commands and runs the check automatically.</p>
</div>
<h3>Core API</h3>
<table class="ref-table">
<thead><tr><th>API</th><th>Purpose</th><th>Example</th></tr></thead>
<tbody>
<tr><td><code>Vec2</code></td><td>Immutable 2D vectors, length, normalize, dot product</td><td><code>Vec2(3, 4).normalized()</code></td></tr>
<tr><td><code>Sprite</code></td><td>Named entity with position, velocity, tags and alive state</td><td><code>Sprite("hero", Vec2(2, 2), "@")</code></td></tr>
<tr><td><code>TileMap</code></td><td>Rectangular collision map; dots/spaces are walkable</td><td><code>TileMap.from_text(level)</code></td></tr>
<tr><td><code>Engine</code></td><td>Fixed-step scene, systems, movement and collision</td><td><code>Engine(world, tick_rate=60)</code></td></tr>
<tr><td><code>raycast</code></td><td>Fast grid DDA ray casting with hit distance and wall side</td><td><code>raycast(world, origin, direction)</code></td></tr>
<tr><td><code>render_ascii</code></td><td>Dependency-free terminal scene preview</td><td><code>print(engine.render_ascii())</code></td></tr>
<tr><td>Canvas renderer</td><td>10 games: shooting, platform physics, racing, grid and brick arcade modes</td><td><a href="games.html#play">Play arcade</a></td></tr>
<tr><td>WebGL2 renderer</td><td>1280×720 live / 4096×2304 9M frame</td><td><a href="games.html#gpu">Open GPU lab</a></td></tr>
</tbody>
</table>
<h3>Your first PyHope scene</h3>
<pre class="terminal"><code>from pyhope import Engine, Sprite, TileMap, Vec2
world = TileMap.from_text("""#####
#...#
#...#
#####""")
engine = Engine(world)
hero = engine.add(Sprite("hero", Vec2(1.5, 1.5), "@"))
hero.velocity = Vec2(0.5, 0)
engine.step()
print(engine.render_ascii())</code></pre>
<p>The visual examples are open source: <code>game.js</code> is the CPU
sprite raycaster, <code>gpu-game.js</code> is the 9M renderer, and
<code>games.js</code> contains Comet Hopper. Original sprites are CC0 in
<code>assets/sprites/</code>.</p>
<!-- ==================== LANGUAGE REFERENCE ==================== -->
<h2 id="language"><span class="badge">09</span> Language Quick Reference</h2>
<p>The full spec (grammar, semantics, error kinds) lives in
<a href="https://github.com/gefrus112/pythonv2/blob/main/docs/LANGUAGE.md">docs/LANGUAGE.md</a>.
Here is the day-to-day core.</p>
<h3>Values</h3>
<table class="ref-table">
<thead><tr><th>Type</th><th>Example</th><th>Notes</th></tr></thead>
<tbody>
<tr><td>number</td><td><code>1</code>, <code>2.5</code>, <code>1e-3</code></td><td>Whole numbers print without <code>.0</code></td></tr>
<tr><td>string</td><td><code>"hi"</code>, <code>f"hi {x}"</code></td><td>Indexed <code>s[0]</code>, tons of methods</td></tr>
<tr><td>bool</td><td><code>true</code>, <code>false</code></td><td></td></tr>
<tr><td>nil</td><td><code>nil</code></td><td>Absence of a value</td></tr>
<tr><td>list</td><td><code>[1, 2, 3]</code></td><td>Mutable; negative indices work</td></tr>
<tr><td>map</td><td><code>{name: "Ada"}</code></td><td>Bare keys, dot access, <code>get(k, default)</code></td></tr>
<tr><td>fn</td><td><code>fn add(a, b): … end</code></td><td>First-class, real closures</td></tr>
<tr><td>range</td><td><code>range(10)</code></td><td>Lazy, from the <code>range</code> builtin</td></tr>
</tbody>
</table>
<h3>Operators</h3>
<table class="ref-table">
<thead><tr><th>Kind</th><th>Operators</th></tr></thead>
<tbody>
<tr><td>Arithmetic</td><td><code>+ - * / // % **</code></td></tr>
<tr><td>Comparison</td><td><code>== != < <= > >=</code></td></tr>
<tr><td>Logic</td><td><code>and</code>, <code>or</code>, <code>not</code></td></tr>
<tr><td>Membership</td><td><code>x in list</code>, <code>k in map</code>, <code>s in string</code></td></tr>
<tr><td>Ternary</td><td><code>ok ? "yes" : "no"</code></td></tr>
<tr><td>Assignment</td><td><code>= += -= *= /= %=</code></td></tr>
</tbody>
</table>
<h3>Statements</h3>
<table class="ref-table">
<thead><tr><th>Statement</th><th>Example</th></tr></thead>
<tbody>
<tr><td>function</td><td><code>fn add(a, b): return a + b end</code></td></tr>
<tr><td>branch</td><td><code>if x: … elif y: … else: … end</code></td></tr>
<tr><td>while</td><td><code>while running: step() end</code></td></tr>
<tr><td>for</td><td><code>for item in [1, 2, 3]: print(item) end</code></td></tr>
<tr><td>range loop</td><td><code>for i in range(1, 10, 2): print(i) end</code></td></tr>
<tr><td>recover</td><td><code>try: risky() catch error: print(error.kind) finally: cleanup() end</code></td></tr>
<tr><td>raise</td><td><code>raise {kind: "ConfigError", message: "port required"}</code></td></tr>
<tr><td>jump</td><td><code>return</code>, <code>break</code>, <code>continue</code></td></tr>
</tbody>
</table>
<h3>Structured error recovery</h3>
<p>Runtime errors are catchable values. A named <code>catch</code> receives a map with
<code>kind</code>, <code>message</code>, <code>line</code>, and <code>trace</code>.
The optional <code>finally</code> block always runs, including during
<code>return</code>, <code>break</code>, and <code>continue</code>.</p>
<pre class="terminal"><code>try:
result = 100 / divisor
catch error:
print(error.kind + ":", error.message)
result = 0
finally:
print("calculation complete")
end</code></pre>
<p><code>raise "message"</code> creates a <code>UserError</code>. Raise a map with string
<code>kind</code> and <code>message</code> fields to create a named application error.
Syntax errors are detected before execution and are not catchable.</p>
<h3>Builtins</h3>
<table class="ref-table">
<thead><tr><th>Function</th><th>Description</th></tr></thead>
<tbody>
<tr><td><code>print(...)</code></td><td>Print values, space-separated</td></tr>
<tr><td><code>len(x)</code></td><td>Length of string / list / map / range</td></tr>
<tr><td><code>range(stop)</code> · <code>range(a, b, step)</code></td><td>Integer range</td></tr>
<tr><td><code>sum</code> · <code>enumerate</code> · <code>zip</code></td><td>Iterable aggregation and pairing</td></tr>
<tr><td><code>all</code> · <code>any</code></td><td>Truth tests across an iterable</td></tr>
<tr><td><code>str</code> <code>int</code> <code>float</code> <code>bool</code> <code>repr</code></td><td>Conversions</td></tr>
<tr><td><code>abs floor ceil round sqrt pow</code></td><td>Math</td></tr>
<tr><td><code>min</code> · <code>max</code></td><td>Over arguments or one list</td></tr>
<tr><td><code>type(x)</code></td><td><code>"number"</code>, <code>"string"</code>, <code>"list"</code>, <code>"map"</code>, …</td></tr>
<tr><td><code>push pop insert remove</code></td><td>List mutation</td></tr>
<tr><td><code>keys values has get</code></td><td>Map access</td></tr>
<tr><td><code>sort sort_by join</code></td><td>Helpers</td></tr>
<tr><td><code>assert(cond, msg?)</code></td><td>Raises <code>AssertionError</code> when falsy</td></tr>
<tr><td><code>json_encode json_decode</code></td><td>Strict JSON for persistent application data</td></tr>
<tr><td><code>args app_info</code></td><td>Application arguments, identity, platform, and capability details</td></tr>
<tr><td><code>read_text write_text append_text</code></td><td>Sandboxed UTF-8 files with atomic replacement</td></tr>
<tr><td><code>file_exists list_dir make_dir delete_file</code></td><td>Safe app-data management</td></tr>
<tr><td><code>read_asset asset_exists ui_message ui_ask</code></td><td>Packaged assets and native dialogs</td></tr>
<tr><td><code>chr ord clock input sleep_ms</code></td><td>Characters, timing, and desktop input</td></tr>
</tbody>
</table>
<!-- ==================== TRY IT ==================== -->
<h2 id="try"><span class="badge">10</span> Try It Right Here</h2>
<p>No install needed to experiment — this is the real interpreter,
running in your browser. Edit and hit Run.</p>
<div class="try-grid">
<div class="try-editor">
<label class="sr-only" for="try-code">Python v2 source</label>
<textarea id="try-code" spellcheck="false">fn fib(n):
if n < 2:
return n
end
return fib(n - 1) + fib(n - 2)
end
for i in range(10):
print(f"fib({i}) = {fib(i)}")
end</textarea>
<button class="btn btn-blue btn-inline" id="try-run" type="button">▶ Run</button>
</div>
<div class="try-out" id="try-output" aria-live="polite"></div>
</div>
</div>
</main>
<!-- ============ footer ============ -->
<footer class="footer">
<div class="footer-inner">
<div class="footer-col">
<h4>Navigation</h4>
<a href="index.html#about">About</a>
<a href="download.html">Downloads</a>
<a href="docs.html">Documentation</a>
<a href="index.html#community">Community</a>
<a href="games.html">Games</a>
</div>
<div class="footer-col">
<h4>Downloads</h4>
<a href="download.html#get">Get the language</a>
<a href="https://github.com/gefrus112/pythonv2/archive/refs/heads/main.zip">Download ZIP</a>
<a href="https://github.com/gefrus112/pythonv2">GitHub repo</a>
<a href="download.html#install">Install steps</a>
</div>
<div class="footer-col">
<h4>Documentation</h4>
<a href="tutorial.html">Tutorial</a>
<a href="guide.html">50-topic guide</a>
<a href="#launcher">Sudbury Launcher</a>
<a href="#windows-apps">Windows EXE builder</a>
<a href="#pyhope">PyHope engine</a>
<a href="#install">Installation</a>
<a href="#vscode">VS Code setup</a>
<a href="#devcontainer">Dev containers</a>
<a href="#any-editor">Any editor</a>
</div>
<div class="footer-col">
<h4>Community</h4>
<a href="https://github.com/gefrus112/pythonv2">GitHub</a>
<a href="https://github.com/gefrus112/pythonv2/issues">Issues</a>
<a href="index.html#news">News</a>
<a href="index.html#events">Events</a>
</div>
<div class="footer-col">
<h4>Success Stories</h4>
<a href="index.html#game">CPU raycaster</a>
<a href="index.html#start">Terminal raycast</a>
<a href="index.html#about">This very website</a>
</div>
</div>
<div class="footer-legal">
<p>
<img src="favicon-v2.svg" alt="" width="22" height="22">
© <span id="year">2026</span> Python v2 Software Foundation™ — a fan-made remake,
not affiliated with the Python Software Foundation. Powered by pure CPU rendering
and stubborn optimism.
</p>
<p class="footer-meta">
<a href="index.html#about">Privacy</a> · <a href="index.html#about">Terms</a> ·
<a href="https://github.com/gefrus112/pythonv2">GitHub</a>
</p>
</div>
</footer>
<script src="pyv2.js"></script>
<script src="site.js"></script>
<script>
// docs page: mini playground + search-in-docs
(function () {
"use strict";
const out = document.getElementById("try-output");
document.getElementById("try-run").addEventListener("click", () => {
const src = document.getElementById("try-code").value;
const r = Pyv2.runCapture(src);
out.textContent = r.error ? (r.output ? r.output + "\n" : "") + r.error : r.output;
out.classList.toggle("error", !!r.error);
});
// search: filter the quick-reference rows, jump to first hit
const params = new URLSearchParams(window.location.search);
const q = (params.get("q") || "").trim().toLowerCase();
const input = document.getElementById("search-input");
if (q && input) {
input.value = params.get("q");
let firstHit = null;
document.querySelectorAll(".ref-table tr, .steps, .checklist li").forEach((row) => {
const hit = row.textContent.toLowerCase().includes(q);
if (hit && !firstHit) firstHit = row;
if (row.tagName === "TR" && row.querySelector("td")) {
row.style.display = hit ? "" : "none";
}
});
if (firstHit) {
const target = firstHit.closest("h2, h3, .doc-section") || firstHit;
(target.closest("h2") || target).scrollIntoView({ behavior: "smooth", block: "start" });
}
}
document.getElementById("search-form").addEventListener("submit", (e) => {
e.preventDefault();
const value = document.getElementById("search-input").value.trim();
window.location.href = "docs.html" + (value ? "?q=" + encodeURIComponent(value) : "") + "#language";
});
document.getElementById("social-btn").addEventListener("click", () => {
window.location.href = "index.html#community";
});
const y = document.getElementById("year");
if (y) y.textContent = String(new Date().getFullYear());
})();
</script>
</body>
</html>