Write Your Python Program
A user-friendly python programming environment for beginners.
The ideas of this environment are based on the great ideas from
Schreib dein Programm!.
- Step 1. Install Python 3.9.x (with x at least 2) or Python 3.10.x..
Note that Python 3.9.0 and 3.9.1 are not supported.
- Step 2. Install the write-your-python-program extension. You need at least Visual Studio Code
- Step 3. Open or create a Python file. The "RUN" button in the taskbar at the bottom will
run your file with the teaching language provided by write-your-python-program.
- By default, the Visual Studio Code extension uses the Python interpreter of the regular
Python extension. If
this is not Python version 3.9.x, you have to configure it explicitly. Configuration
can be done either by selecting the desired Python version in the left corner of the status
bar (at the bottom of the window), or by setting the path the the python
executable in the settings of the plugin.
- The extension disables linting of Python code when activated. This is well-suited for beginners
but might cause unwanted effects when you rely on linting. In such cases, you have to
deactivate the extension.
Usage without Visual Studio Code
Write Your Python Program can be installed outside of Visual Studio Code via pip:
pip3 install wypp
This needs Python 3.9.x. After installation, you can use the
for running your python files, making all features explained below available.
wypp --help for usage information.
Here is the Changelog.
- Breaking change in version 0.12.0 (2021-09-28): type annotations are now checked
dynamically when the code is executed.
This behavior can be deactivated in the settings of the extension.
- Breaking change in version 0.11.0 (2021-03-11): wypp is no longer automatically imported.
You need an explicit import statement such as
from wypp import *.
Here is a screen shot:
When hitting the RUN button, the vscode extension saves the current file, opens
a terminal and executes the file with Python, staying in interactive mode after
all definitions have been executed.
The file being executed should contain the following import statement in the first line:
from wypp import*
Running the file with the RUN button makes the following features available:
You can define enums, records and union data types and the use them with the
type hints of
Python 3. Type hints are checked for correctness dynamically, i.e. violations
are detected only at the moment when a function is applied to an argument not matching
its type hint or when a function returns a value not matching the return type hint.
(This approach is similar to
contract checking in racket)
Color = Literal['red', 'green', 'blue']
You work with a record like this:
p = Point(2, 3) # point at x=2, y=3
print(p.x) # Prints 2
Fields of records are immutable by default. You get mutable fields with
Mixed Data Types
PrimitiveShape = Union[Circle, Square]
To use recursive types, you need to write a forward reference to the yet undefined type
as a string:
Shape = Union[Circle, Square, 'Overlay']
Case distinction works like this:
def workOnShape(s: Shape) -> None:
if isinstance(s, Square):
# s is a Square, do something with it
elif isinstance(s, Circle):
# s is a Circle, do something with it
elif isinstance(s, Overlay):
# s is an Overlay, do something with it
The body of
workOnShape can safely assume that
s is indeed one
Overlay because the type hint
Shape for argument
s is checked dynamically. Here is
what happens if you apply
workOnShape to, say, a string, that is
Traceback (most recent call last):
File "test.py", line 42, in <module>
WyppTypeError: got value of wrong type
expected: value of type Union[Circle, Square, Overlay]
context: workOnShape(s: Union[Circle, Square, Overlay]) -> None
declared at: test.py:31
caused by: test.py:42
Tests are defined via
check. The first argument of check is the actual result,
then second argument the expected result.
All python types (builtin or from the
typing module) can be used as annotations.
Also, you can use every class as a type. In addition, WYPP comes with the following
The code is run with
from __future__ import annotations
(see PEP 563), which will be
the default from python 3.10 on. This means that you can use a type as an annotation
before the type being defined, for example to define recursive types or as
the type of
self inside of classes. In fact, there is no check at all to make sure
that anotations refer to existing types.
list[T] the following operations are typechecked:
list[idx] = value
list += [...]
for i in list: (Iterator)
set[T] these operations are typechecked:
set.remove(value) Value must be of
value in set Value must be of
for i in set: (Iterator)
dict[K,V] the supported typechecked operations are:
Note: In contrast to the standard library
default is required, to avoid inserting
None as value into otherwise typed dicts.
key in dict Key must be of
for k in dict (Iterator)
dict[key] = value
Module name and current working directory
When executing a python file with the RUN button, the current working directory is set to
the directory of the file being executed. The
__name__ attribute is set to the value
Bugs & Problems
Please report them in the issue tracker.
You can debug the extension from Visual Studio Code:
- Open the main folder of the plugin with vscode.
- Open the file
- Choose "Run" from the menu, then "Start Debugging".