Welcome

It is my hope that this guide will manage to assist you in getting started with the Python programming language. While the need to indent may seem daunting, and the command line may not be your strong point, it is my hope that when you finish reading through the "Getting Started" section you will be able to at least understand how Python development looks like and what it entails. I hope that, after reading through this tutorial, you will be able to clearly define your reasons for working (or avoiding) the language, and not rely on hearsay which can at times be very misleading.

Some Assumptions

This guide is not aimed at someone who does not know how to use a screen reader. While I do intend to provide detailed instructions, said information will only be available for new topics. In other words, this tutorial assumes that whoever decides to read through it is competent at using assistive technology and is comfortable with their own PC and the internet. Furthermore, as of this point, the instructions assume that you are on a Windows environment. Future alternatives may be added, but as of now I only have access to a Windows machine and thus only am able to verify the accuracy of the material concerning Windows.

Work In Progress

Some parts may be incomplete. Some sections may lack clarity. If you find a problem with a particular set of instructions, do let me know either on the forum or the repository itself.

Downloading and Installing Python

The first thing you should do is download Python to your computer. While it is certainly possible to code online using something like Free Code Camp, most development will occur on your PC. As such, head over to Python.org, scroll down to the "Download" heading, and click on the latest version link. After that, it is as simple as selecting your operating system of choice (Windows in my case) and whether the interpreter will be 32 or 64-bit. (If you are not sure of what your windows machine can support, check out this link for some instructions on figuring that out)

Installation

After downloading Python, the next step is to actually install it. If you chose to download the zip version, you can disregard this section. However, do note that in order to successfully follow this guide you should have Python within your environment variables. You can find some instructions on how to do this here.
After launching the installer, select the "Customize installation" option. Uncheck the "py launcher" checkbox. While being convenient (it allows you to type things like

py myscript.py

), having multiple Python versions will cause the launchers to conflict, potentially misleading you when trying to debug code. If you don't have administrator permissions, uncheck the "for all users" checkbox, and then click next. Uncheck "Create shortcuts for installed applications," and select "Add Python to environment variables" and "Precompile standard library" options. You are technically free to leave the installation directory unmodified, but I have experienced issues with Python being unable to access the default directory do to lack of administrator privileges and henceforth always change the location to somewhere where I am certain of the lack of necessity for elevated permissions. After resolving the dilemma of Python's habitat, click on the "Install" button and wait for the success dialog. Congratulations! You now have Python on your machine!

Verifying That it Actually Worked

In order to ensure that Python has been successfully installed, do the following (See the next chapter for an explanation of what you are actually doing)

  • Press windows+r
  • type in cmd and press enter
  • At the resulting prompt, type in python. You should now get text that looks somewhat like this:
Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

If you get output like "'python' is not recognized as an internal or external command, operable program or batch file," you need to edit your environment variables to include python within your path. See the previous section on how to do this. If everything worked successfully, you are now ready to proceed to the next chapter. Note that you must type exit() or quit() to shut down the interpreter.

Editors, Scripts, and Miscellaneous Screen Reader Configuration

While you can certainly write scripts in a notepad (I have for a year or so), there are a multitude of editors available for working with Python. Said tools allow for features like autoindentation, autocompletion, and can go as far as supporting type annotations and providing helpful hints as you are calling functions. If this sounds like gibberish, don't worry. You can always switch to something new later. Unfortunately, do to the extensive amount of options, this guide will only list the available tools and provide comments as necessary rather than give details on installation and setup for each product.

Editor and IDE listing

  • Notepad II
  • Notepad ++, provides autocompletion and autoindentation while converting tabs into four spaces (adjustable). A quick search for "Python extension for notepad ++" yielded this link for completion of standard Python library functions. See this link on how to run Python using Notepad ++ without needing to resort to commandline.
  • EdSharp, lacks the ability to save empty files but works well otherwise
  • VSCode, has a medium learning curve and requires an extension like Microsoft Python in exchange for providing excellent debugging tools, integration with Git, indentation, and completion.
  • PyCharm, may require Java and Java Access Bridge. Be sure that the version of Java you install matches that of your system, I.e, 64-bit installation for a 64-bit machine. Upon launch, PyCharm should prompt you to turn on screen reader mode if you are running any assistive technology, I.e, NVDA or Jaws.
  • Visual Studio Community, big and clunky at times and does not guarantee accessibility of its profiler and debugger, but works well when it does. Note that you will have to install this and the C++ Desktop Development extension should you choose to Cythonize your code. Also note that just like with VSCode, you will have to install a seperate extension to enable Python support, though this time the said package is in the installer itself. If you experience lag with NVDA while using the IDE, try turning on "Enable selective registration for UI Automation events and property changes" in the advanced section of your NVDA preferences. It may or may not help.

Running Code From the Commandline

Regardless of what option you chose, knowing how to interface with the Python interpreter is a valuable skill. If you want to test something out, whether a particular standard library module has a specific function, for instance, the interpreter can be of grate help. If you are not sure of what a commandline is, a quick skim through this article should clear up the mystery.

Great, How Do I Open and Use This Thing?

To open up your commandline, press windows+r to bring up the run dialog, type cmd, and hit enter. You should now see something like the following:

Microsoft Windows [Version 10.0.19041.685]
(c) 2020 Microsoft Corporation. All rights reserved.

C:\Users\yourUsername>

You are now in the command prompt and the system is waiting for your input. If you type "dir" without the quotes, you will get the listing of all the files and folders within your directory. Typing a filename by itself, such as some_file.txt, will cause said file to open within its associated app, Notepad ++ in my case. Typing "cd directory_name" will cause you to move to the desired directory. Typing "cd .." will move you back to the previous folder. Think of it as a tree where each directory is a branch and it holds other branches (directories) which you could move to and leaves (files) which you can only look at or manipulate. So, using my analogy, typing "cd branch_name" moves you to said branch, and typing "cd .." will cause you to return to the branch your current branch is connected to. This is not entirely accurate (the branches don't have to be linked in order for you to be able to move to them), but this should help you understand how the commandline works.
The above paragraph may seem slightly confusing, so I will provide a practical example. Suppose you open up your commandline, type in "dir", and see that you have a folder called some_awesome_thing. Not knowing what it contains, you type "cd some_awesome_thing" and watch as your path is updated to be "C:\Users\yourUsername\some_awesome_thing>". Typing in "dir" once again shows you that there is a single folder, creatively called thing, inside this directory. Your curiosity still unsatisfied, you type in "cd thing" and once again ping the directory for its contents by typing "dir". This time, you only see a file, called run_me.py. Finally satiated with said knowledge, you type "cd .." twice to return you back to your starting point. Note that you could also have typed "cd c:\users\yourUsername", but I chose to use the first method do to its simplisity.

Wait, Do I Have To Type All These Names?

No, you certainly do not. The commandline has a nice feature where you can type in a part of the desired path and press tab to have it fill out the rest for you. You can keep pressing tab and cycle through the available suggestions. In the previous example, you could have just typed in "cd ", do note the trailing space after cd, and pressed tab to go through all of the available directories rather than use dir to find out what is inside your folders.

Why the Underscores?

I chose to use underscores (_) to remove the necessity of surrounding your arguments with quotes. The commandline will equally accept some_awesome_thing or some awesome thing, but it will require the latter to be surrounded in quotation marks, I.e, "some awesome thing"

A quick note

I have been surrounding the commands dealing with commandline input with quotation marks, but this is not how you will see cmd input being notated on the internet. Typically you will see a dollar sign ($) before the desired command, I.e:

$dir
$cd some_awesome_thing

Going forward, this is how I will notate commandline input as well. I feel like this is a given, but if you are copying the example commands, remove the dollar sign in order to make them work.

Back to Your Regularly Scheduled Conversation With the Interpreter

After getting familiar with the commandline, we can now continue to discuss how to run code outside of special editors. As I have previously mentioned, Python interpreter can help out with quick testing, so that is what we will begin with. Open up your commandline and type in the following:

$python

You should now see something similar to the following text:

Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

If you get text like 'python' is not recognized as an internal or external command, operable program or batch file, refer to the previous chapter for some pointers regarding adjustment of your environment variables.

Printing Text

Before we shut down the interpretor, let's say you wanted to verify that the print function works as expected. Type in the following into your console (Don't leave anything out, parentheses and quotes are important!).

print("Hello, World!")

If you get silence as your output and are using NVDA, press NVDA+5 to turn on reporting of dynamic content changes and try again. If you are using Jaws, reviewing the screen is a matter of scrolling with your Jaws cursor (JAWS+RightBracket). You should now get the classic introduction to programming message. If you get an error, make sure that all the quotes and parentheses are present and that you didn't accidentally misspell print. If it still doesn't work... well, I hope you had fun, because the world is about to end and Python refuses to speak do to the impending apocalypse.
Regardless of the outcome, to close the interpreter, you can simply type

exit()

or

quit()

and you will be returned to the comforts of the command prompt.

Running Larger Code Chunks

The interactive console is great for quick tests, but it ddoes not work too well for larger projects. Fortunately, Python provides an easy way to run large scripts from the commandline. Start by opening your command prompt and navigating to the desired directory where you wish for the script to reside in and type in the following:

$echo.>your_script_name.py

This creates an empty file, your_script_name.py, which you can then open with your desired editor. Edit your file to look like the following:

print("Hello, Commandline!")

After saving the file, go back to your command prompt and type the following:

$python your_script_name.py

You should get the output of "Hello, Commandline!". If you are greeted with silence and are using NVDA, make sure you turned on the reporting of dynamic content changes by hitting NVDA+5. If that still does not work, read on to see how to review your screen

Reviewing the Screen

At times, your script may exit silently without giving you any output to work with. This is do to your speech being interrupted as your focus switches back to the commandline. To that end, here is the solution to seeing silent errors

Using NVDA

  • If you are using the laptop layout, use NVDA+PageUp and NVDA+PageDown until you hear "Object review". After object review has been selected, use NVDA+Up and NVDA+Down arrow keys to review the command prompt screen. Your cursor typically starts at the bottom and thus you may need to scroll upwards to see the error and the traceback.
  • If you are using the desktop layout, use NVDA+Numpad7 and NVDA+Numpad1 until you hear "Object review". After object review has been selected, use Numpad7 and Numpad9 to review the command prompt screen. Your cursor typically starts at the bottom and thus you may need to scroll upwards to see the error and the traceback.

Using Jaws

You can use the standard Jaws cursor (JAWS+RightBracket) to review the last couple of messages. (Thanks Defender for supplying this tip)

Miscellaneous Settings

Indentation

It is very common to see complaints about the necessity to keep track of tabs and spaces. Fortunately, both NVDA and Jaws screen readers provide a solution to this issue.

Using NVDA

To turn on indentation reporting, go into your NVDA preferences, click on settings, scroll down to document formatting, and press Alt+I. This will bring you to a combo box where you can choose how NVDA notifies you of indention (speech, tones, or both). After selecting your desired method, scroll down and press apply before clicking okay to close the settings dialog.

Using Jaws (Thanks Defender for supplying this tip)

Method 1
  • Go to JAWS settings center (JAWS Key plus 6) and either set it for the current application only or use control shift D to make it system wide.
  • Hit shift tab and Type "indent" into the search box.  The only option which comes up is the one you want. You may also want to go into the settings center search box and type "speech and sound" for the speech and sounds category.  There you can change the default scheme by pressing space until it matches the number of spaces that your code editor considers to be a tab if it doesn't seem to be reporting properly.
Method 2

When within the window of your editor, use JAWS Key plus V, shift tab and type "indent" again, then set the option to indicate. You may also want to go into the settings center search box and type "speech and sound" for the speech and sounds category.  There you can change the default scheme by pressing space until it matches the number of spaces that your code editor considers to be a tab if it doesn't seem to be reporting properly.

Testing Indentation

To verify that indentation reports work, read through the following piece of Python code.

def main():
    print("I will now count to 10!")
    for i in range(1, 11):
        print(i)
    print("Alright, all done now!")

main()

Symbol reports

It is common to need to find a mistake in regarding unmatched parentheses within Python code. NVDA and Jaws provide a variety of symbol reporting options to assist in this endeavor. For NVDA, you can toggle through said choices with NVDA+P. For Jaws, you need to navigate to the settings center and search for customize punctuation (Thanks Defender for supplying this tip). I personally find the most option to be the most helpful (I think that reading out commas and periods is unnecessary), but you may differ in that regard. To that end, the code below can be used as a testing method for the various settings

def print_3d_list():
    matrix = [[[k for k in range(10)] for j in range(10)] for i in range(10)]
    for i in range(len(matrix)):
        for j in range(len(matrix[i])):
            for k in range(len(matrix[i][j])):
                print("Current coordinates: (%d, %d, %d)" % (i, j, k))
                print(f"Current element: {matrix[i][j][k]}")

print_3d_list()

That's It!

Now that you have an editor and know how to use Python from the commandline, you can proceed to the next section where I have compiled a list of tutorials for you to get started programming. I certainly don't recommend going through all of them at once, better to stick to one method of learning unless you get stuck, but if something does not make sense, feel free to try something else or switch to something new. Just because you chose a specific book or course does not mean that you have to be purely devoted to its methods of teaching. If an explanation seems confusing, chances are that there is a better one out there and you just need to look for it

Attribution

This section would not be complete without input from the community. In particular, Defender provided instructions regarding Jaws commands for indentation, symbol reporting, and reviewing commandline output. If the instructions here are unclear, his original replies are located in this thread, posts 3 and 5.

Programming Tutorials

Below are some resources for getting started with Python programming.

Game Frameworks and Libraries

Before we can continue, do note the title of this section. When it comes to making games, there is a difference between an engine and a framework. Engine provides you with things like collision and graphics. a framework does not. They are often created for one specific goal and can only fulfill tasks similar to the original exigence. I point this out because a lot of people seem to misuse the terms and that has been bothering me for some time.

A Delicate Warning

If you are coming to Python from a language like BGT, I urge you not to take shortcuts. Learn the actual language. Figure out why classes with actual methods are important. Understand inheritance. Don't look for things that you are familiar with. They exist, but BGT practices paradigm is awful for reasons that will be discussed later. Most of these resources are trivial to make and few provide ease of modification. If you are okay with this, go ahead. Use them. I won't--certainly can't--stop you. However, know that you are already limiting yourself to very specific constraints without writing a single line of code.

Resource Listing

Earwax

Earwax, found here, comes with a lot of features one would typically want for games. Menus, input boxes, basic collision, sound playback, configuration... the only downside is the fact that it makes extending the library rather difficult. Earwax is heavily aimed at those who are comfortable with decorators, going so far as using them to modify its own classes. This is partially why it is so hard to extend. In a nutshell, the presented classes cannot have user-created constructors, which means that any new values created by the user must account for None or the equivalent of being empty. Its discussion thread can be found here, and a bigger example of it being in use can be found here. Though the creator has not officially abandoned the project, he did mention that he was not sure how much more he was willing to add (see post 166 of the earlier thread). The engine uses Pyglet for handling game events, Synthizer for sound output, and Cytolk for providing speech.

Lucia

Lucia found here aims to bridge the gap between BGT and Python by providing identical function names like key_pressed and sound encryption. The framework uses Pygame for handling game events, Sound Lib for sound output, and Accessible Output 2 for providing speech. The library also requires you to write your own game loop and does not provide tools to keep track of framerate. In addition, the underlying sound pool does not support asset caching, which means that sound buffers get loaded into memory every time a sound is ordered to play instead of being reused. Finally, Lucia's utilities for creating menus and receiving user input block, which makes it difficult to use a state stack to propagate events. its discussion thread can be found here, and its development status is somewhere between abandoned and rarely updated. Some examples can be found here and an actual game using the framework can be found here

PyAge

PyAge, found here aims to provide as little as possible with the goal of being agnostic. It offers a state stack, a skeleton of a menu, text input, and the ability to customize almost anything one wishes. By default, PyAge uses Pygame for handling events, Synthizer for sound output, and Cytolk for providing speech. Its discussion thread can be found here, but unfortunately there are no examples within the repository or the linked topic. However, the code is commented and there is a basic explanation of the API usage. Unlike Lucia, PyAge does offer the concept of framerate as well as a screen stack. It also provides the ability to schedule tasks and bind functions to keys, both on a state-by-state basis and globally (regardless of what is currently happening inside the game). It should be noted that the framework heavily relies on the Singleton pattern.

Pygame

Pygame, found here, is a framework designed for creating games using Simple Direct Media Layer (SDL) under the hood. Though not coming with any tools specifically aimed at audio game creation, it allows for the greatest level of customization. There are no official discussion threads, but the documentation contains numerous code snippets and Google can provide larger samples of games made with Pygame. Also do note that you will have to choose sound and speech backends as Pygame does not offer the ability to send messages to a screen reader and its sound support is minimal at best.

Pyglet

Pyglet is one of Pygame's competitors. Found here, it encourages the usage of decorators with the ability to inherit from classes at one's discretion. As with Pygame, Pyglet does not offer specialized tools aimed at audio game creation. However, it does offer a sound backend, OpenAL, which supports binaural audio. pyglet also comes with its own control loop and scheduling functions, automatically keeping track of the provided framerate. There are no official discussion threads, but the documentation contains numerous code snippets and Google can provide larger samples of games made with Pyglet. Do note that you still need to choose a speech and possibly a sound backend if OpenAL is not what you desire when using the framework.

PySDL2

PySDL2, found here, is a set of Python Bindings for Simple Direct Media Layer (SDL). The library is almost identical to its C counterpart and offers little functionality beyond what SDL can do. In exchange, it provides the greatest amount of customization. It should be noted that there are no official discussion threads, and that most of the examples for the library on Google are in C and C++.

So, which one should you use?

I strongly urge using Pygame, Pyglet, or PySDL2. Though having menus is great, it becomes extremely painful to realize that the framework you're using as your game system does not support what you want to do. Even more disparaging is the fact that often than not, what you are using cannot easily be modified. Writing your own system from scratch is the best option, regardless of difficulty. You will know how it functions. You will design specific tools that you could customize to fit your vision. Finally, you will learn what happens under the hood when you create your desired architecture. If you must choose an engine, go with PyAge. It offers very minimal support and leaves most of the implementation up to the user. It offers so little that you may as well write your own module and gain a deeper understanding of game systems in the process.