So far, we believe that you have gained an understanding of basic operations of Windows and NVDA, as well as browsing websites. From here, we will try using “Google Colaboratory”, which is also the objective of this chapter.
Google Colaboratory (often abbreviated as Google Colab or simply Colab) is one of the environments for running the programming language “Python”.
Normally, to use Python, you would have to:
These steps are quite complicated. In particular, there are many things you need to know when you set up initially or when you use the “Command Prompt”, and it takes time to learn them.
On the other hand, Colab works in a browser, so it can be easily used from any computer. In addition, tools that can be used for data analysis, which you will learn in the latter half of this content, are already prepared.
However, to use Colab with NVDA, some familiarity is necessary. Therefore, as the final stage of programming preparation, you will operate Colab with NVDA and a keyboard to get the hang of it.
First, we will explain the main terms and concepts used in Colab.
The data created using Colab is called a “notebook”. Thus, you will perform operations such as “saving a notebook” and “opening an existing notebook”.
If you were to compare it to other apps, it would be something like a “document” in Microsoft Word or a “workbook” in Microsoft Excel. Even if you can’t understand these terms, there’s no particular problem. It’s sufficient to understand that you’re creating a notebook using Colab.
In a notebook, you can include:
You can also combine multiple of these.
That is, you can store a series of data in a single notebook, such as:
Earlier, we explained that various data can be stored in a notebook. Each piece of this data is managed in a unit called a “cell”.
A cell, in English, means a “small room” or a “cell”. Those of you who use Braille might call one character of Braille a “cell”.
In Colab, there are cells for:
Each has its own uses. Depending on what you want to write, you will decide which cell to use.
Cells for writing Python programs are called code cells and have the function to “execute” the written program. The most commonly used is the “cell for writing a Python program”.
On the other hand, cells for writing text, called text cells, have functions such as editing documents and inserting images into documents. While you may not use these cells often, remember that such cells exist and learn the basic operations (explained later).
So far, we’ve learned that NVDA has two modes: “browse mode” and “focus mode”. When operating Colab, we basically use “focus mode”. Immediately after opening a page, NVDA will automatically switch to browse mode. Therefore, as soon as the page finishes loading, stop the reading with the Ctrl key, and press NVDA+Space to switch to focus mode. From here on, we will proceed with the assumption that you are in focus mode.
Now let’s get started with Colab.
When you open the Google Colaboratory page, a notebook titled “Welcome to Colaboratory” will automatically open. This is like an introduction to Colab.
While you can read some of the content of this page in browse mode, it won’t give you practice with Colab, so let’s dare to use it a bit in focus mode.
First, let’s go through the cells, which are the components of a notebook, in order. Right after loading the page, press the down arrow key once.
Below, the expected readout is provided. However, if you have installed the NVDA addon prepared for this content, as mentioned in the NVDA installation section, please note that a considerably abridged content will be read out.
Move cell up Ctrl+M K Move cell down Ctrl+M J Link to cell Edit Mirror cell Delete cell Ctrl+M D Other cell operations Collapse the 4 child cells below this section header (pressing <Shift> will also collapse sibling sections) Introduction The document you are viewing is not a static webpage but an interactive environment called a Colab notebook where you can write and execute code. For example, the following code cell contains a short Python script that calculates a value, stores it in a variable, and outputs the result. Section
Now, press the up arrow key in this state.
Move cell up Ctrl+M K Move cell down Ctrl+M J Link to cell Edit Mirror cell Delete cell Ctrl+M D Other cell operations Colaboratory logo What is Colaboratory? Colaboratory (abbreviated as Colab) is a service that allows you to write and execute Python from your browser. It has the following features: No need for environment setup Free access to GPU Easy sharing Colab helps streamline the work of everyone from students to data scientists to AI researchers. For more information, watch our introduction to Colab. You can also start using it right away by clicking on the link below. Section
If you haven’t installed the NVDA addon, the reading may be too long and you might have felt overwhelmed halfway through. But if you patiently listen to the whole thing, you will hear readings like “The document you are viewing is not a static webpage but”, which you can understand.
In fact, at this point, the up and down arrow keys are used to “move between cells”. And if you keep listening to the reading, it will start reading the content written in the currently selected cell.
The two cells that were just read out were text cells for writing text (normal documents for people to read). With that in mind, press the down arrow key and then the up arrow key in turn and listen to the reading.
The cell labeled “What is Colaboratory?” is at the top of this notebook, that is, at the top. And it’s followed by a cell labeled “Introduction”.
Reading the second cell, it says, “For example, the following code cell contains a short Python script that calculates a value, stores it in a variable, and
outputs the result.” So, the next, or third, cell should be a code cell for writing Python programs.
Then press the down arrow key to look at the third cell.
Move cell up Ctrl+M K Move cell down Ctrl+M J Link to cell Open editor settings Mirror cell Delete cell Ctrl+M D Other cell operations Run cell seconds_in_a_day = 24 * 60 * 60 seconds_in_a_day Clear output Execution time: Unknown time Section
As expected, a program has appeared. At this point, it’s okay not to think about what this program is.
With the above operations, it’s possible to read the content while moving between cells. However, if you’re going to write your own program, of course you need to be able to edit the contents of a cell.
First, press the up arrow key twice to move to the first cell. Then press the Enter key. You will be read out as follows. As before, if you have installed the NVDA addon, a simplified content will be read out.
Editor content;Press Alt+F1 for Accessibility Options. <p><img alt="Colaboratory logo" height="45px" src="/img/colab_favicon.ico" align="left" hspace="10px" vspace="0px"></p>
Everything other than “Editor content;Press Alt+F1 for Accessibility Options” is the content written in this cell. In this state, you can move character by character or line by line by pressing the cursor keys up, down, left, or right.
Note that what’s written in this cell is a document called “HTML”, which is used to create web pages, and it contains a lot of less-than and greater-than signs (known as “less than” and “greater than”). It’s good to know that there are document formats like this with a lot of less-than and greater-than signs.
When you’re done editing (or checking) a cell, press the Escape key. This will allow you to move between cells with the up and down arrow keys, just like at the beginning.
Since we’re at it, let’s take a peek at a Python program as well. The third cell contained a program. Select the cell, press Enter, and read the program.
There is one thing you need to be aware of when you select a cell and press Enter to enter edit mode. That is the behavior of the up and down arrow keys.
If you press the down arrow key at the bottom of a cell, it moves to the last line where the cursor was in the cell below. Similarly, if you press the up arrow key at the top of a cell, it moves to the last line where the cursor was in the cell above. The point is that it “moves to the line where the cursor was last”.
For simplicity, let’s say there’s a notebook made up of two cells, which we’ll call the “upper cell” and the “lower cell”. You performed the following operations on this notebook.
After these operations, the cursor moves to the first line of the “upper cell”. This is because the “upper cell” is above the “lower cell”, and the last place the cursor was in the “upper cell” was the first line.
Now let’s actually try programming using Colab.
Before programming, there are a few things you need to prepare. Specifically, you need to:
First, you need to create a notebook to write and save your new program. Please follow these steps:
When you execute this menu item, you always need to press NVDA+Enter.
Now you have a new notebook called “Untitled0” (the number at the end may vary depending on the situation).
Right after creating a new notebook, a code cell has already been created and is in editing mode. However, you will need to perform the operation of inserting a new cell in the future, so let’s understand the method.
With these steps, a code cell has been added to the bottom of the notebook, and you can edit this cell. Press Escape and then the up and down arrow keys to check.
At this time, if you press the “Text” button instead of the “Code” button, you can add a text cell.
Also, there is another way to add a cell:
This will add a code cell. If you wanted to add a text cell, press Escape and then Ctrl+M, followed by M. This will convert it to a text cell. Press the up and down arrow keys to check.
Put a code cell into edit mode and try entering the following program:
print("Welcome to the world of python programming!")
In programming,
it’s important to be aware of the type of characters. Also, at this stage, there is no need to understand the program itself, so there is no particular problem with copying and pasting the above program.
Once you have entered a program into a cell, try executing this program with the following steps:
These are the steps from running the program to checking the results. Try rewriting the content of the program and doing it a few times to get used to it.
As you continue with programming, you might create a program that does not work properly. There are two types of states of “not working properly”: one where the result does not come out as expected, and the other where the program cannot be executed at all. In the case where the program cannot be executed, a message is displayed stating, “The program cannot be executed for this reason”. Let’s see how this display looks.
Please erase the previous program and try entering the following program:
print("Welcome to the world of Python programming!"))
This program is similar to the previous one, but an additional closing parenthesis is added at the end. In general, in a program, you cannot close a parenthesis that has not been opened, and an opened parenthesis must always be closed. Therefore, this program is grammatically incorrect.
When you check the execution result in the same way as before, the following will be displayed:
File "<ipython-input-2-db5401d92260>", line 1
print("Welcome to the world of Python programming!"))
^
SyntaxError: invalid syntax
The detailed display changes depending on the situation, but it is sufficient if you can confirm the display “SyntaxError: invalid syntax”. It means that the syntax is invalid.
As you can see, program errors are displayed in English. Some people may not be good at English, but don’t worry as it doesn’t use difficult words. Also, if you search the internet with keywords like “python SyntaxError: invalid syntax
”, you may find explanation pages.
As you can see from the operations so far, the result of various executions in Colab cannot be understood until you actually operate the screen reader and have it read out. Therefore, there is a library that notifies the success or failure of execution results by sound so that you do not have to go back and forth between the code cell and the result. In data science, there are often time-consuming processes, and there are features such as informing the progress of the process by the pitch of the sound.
Let’s try it out below. Run the next cell. Once the execution is completed, from then on, when you run a cell, you will hear a beep sound, and when an error occurs, you will hear a buzzer sound.
!pip install -q colab-a11y-utils # Install the library
import colab_a11y_utils # Import the library
colab_a11y_utils.set_sound_notifications() # Execute the library
Try running the following code. After 5 seconds, you should hear a beep sound confirming the end of execution.
import time # Import the time library
print("Start")
time.sleep(5) # Pause for 5 seconds
print("End")
The execution result should be as follows:
Start
End
Next, let’s intentionally cause an error. Can you hear the buzzer sound?
plint("Example of a typo") # An example of an error caused by a typo
Google Colab is an environment that allows you to easily run Python code in your browser without the need for initial setup or complex procedures. It also provides tools that can be used for data analysis and more. When learning programming or data science, it is beneficial to make use of such environments to avoid getting stuck on non-essential tasks like environment setup.
In this chapter, we learned the basics of creating a new notebook, adding cells, inputting and executing code, and checking the results. We also introduced a tool called sound notification library, which is specifically designed for screen reader users. While the accessibility of Colab is not yet sufficient, by utilizing such tools and adapting the operating methods, it is possible to make effective use of it.