At My Fingertips

Documentation

Learn How to Use the Toolbox

Abstraction is at the core of programming. PyTamaro's design reflects the paramount importance of abstraction.

You might have realized that the library itself is particularly small in terms of the number of functions it provides. This means that you have to write the code to create almost all but the very basic graphics: a good opportunity to develop your programming skills!

As you progress through the activities, you will create increasingly complex graphics. You might find yourself implementing the same functionality over and over again. For example, a number of activities need squares to be completed. How can you avoid writing the same code again and again, or copy-pasting it from one activity to another?

What is a Toolbox?

Just like a wise handyperson carries a toolbox with them with all the items they need, you can leverage PyTamaro's toolbox to conveniently store and retrieve your Python functions.

Photo of red toolbox by jeanvdmeulen on pixabay.

Adding a Function to your Toolbox

Complete the code below to define a function that creates a square of a given side length and color. Use the rectangle function. When a cell of code defines a function, an icon depicting a hammer and a wrench appears in the bottom right corner.

Try to click on it. A new dialog will appear, asking you to select which of the functions defined in the cell you want to save. Pick the appropriate one (square, in this case) and write a short description of what it does, to help you remember it later.

You will also want to test that your function behaves as you expect. Complete the "usage" example by adding an example call to your function. The platform automatically adds the import statement you need. Run the usage example, make sure that no error is reported, and finally save the square function to your toolbox.

Loading...

Using a Function from your Toolbox

Your toolbox should now contain a function named square. All the functions in your toolbox are shown in the left sidebar.

You can use the functions from your toolbox in any activity. Import them like you would import any other function in Python:

from toolbox import <name>
Loading...

What You Learned

You now know how to add a function to your toolbox and how to import it in any activity.

This platform makes it particularly easy to reuse a function, but you can achieve the same result also in a normal Python environment. In a simplified worldview, you can think that an import statement in the form from toolbox import f is just importing the name f from a file named toolbox.py in the current directory.

Learn How to Use the Toolbox

Logo of PyTamaro

PyTamaro is a project created by the Lugano Computing Education Research Lab at the Software Institute of USI

Privacy PolicyPlatform Version 0d7866a (Fri, 20 Dec 2024 07:46:38 GMT)