python_taPythonTA is a Python program that analyses Python code to help
students find and fix common coding and style errors. Unlike testing
libraries like doctest or pytest, PythonTA
does not actually run your code. Instead, it analyzes the program text
directly, looking for common patterns of code that often lead to
errors.VS Code does something very similar, which is why
you’ll see red or yellow highlighted text in your Python files as you’re
working, before running the file.
To run PythonTA on a Python file, put the following code at the bottom of the file you want to check:
if __name__ == '__main__':
import python_ta
python_ta.check_all()When you run this file, you’ll see a report open up in your web browser that shows any errors that PythonTA detected. These errors are divided into two broad categories:
Cmd+Shift+P on macOS, Ctrl+Shift+P on
Windows) and run Format Document to automatically fix common formatting
issues in your current file when a formatter is available.We recommend running PythonTA regularly as you’re working on an assignment, as it can be a useful way to check your work and improve the quality of your code. If you’re ever stuck, try taking a break and running PythonTA and fixing any errors it finds for you! This is a way to develop good programming habits and style, which will come in handy in this course (and all future courses).
When you run PythonTA, it generates a new report file called
pyta_report.html in the same folder as the file you’re
checking. After you’re done running PythonTA, you can safely delete this
report file.