![]() ![]() You can see more examples, more information about how the tracebacks are implemented, and other tools you can use in your debugging in the Python 3.11 preview tutorial Even Better Error Messages. These tracebacks make debugging in Python 3.11 easier than in earlier versions. In the latest version of Python, you see immediately that the issues are caused by second. from_dict() twice, it normally would require some effort to figure out if the error was raised when processing first or second. However, take note of the traceback from within convert_pair(). Trying to encapsulate Ada raises the same KeyError as earlier. > convert_pair ( programmers, programmers ) Traceback (most recent call last):įile "/home/realpython/programmers.py", line 24, in convert_pair return Person. Start by reading the information from the JSON file: You’ll create a class that can wrap this information. To top it off, you’ve only recorded Uncle Barry’s first name. Naturally, you only have birth information about Guido van Rossum. While the information about Grace Hopper and Ole-Johan Dahl is complete, you’re missing Ada Lovelace’s day and month of birth as well as her year of death. Note that the information about the programmers is quite inconsistent. Assume you have a file named programmers.json with the following content: To appreciate the power of the improved tracebacks, you’ll build a small parser of information about a few programmers. They may be able to convey information that you couldn’t get from the traceback by itself before. However, the annotated tracebacks are even more powerful if your code is more complex. Getting this extra help in spotting mistakes is useful. The actual culprit is calling inverse(0), as 0 has no inverse. In this example, a ZeroDivisionError is caused by the division 1 / number. ![]() As usual with tracebacks, you should start at the bottom and work your way up. They’re used to guide your attention to the code that’s causing the error. ![]() Note the ^ and ~ symbols embedded within the traceback. Traceback (most recent call last): File "/home/realpython/inverse.py", line 6, in print(inverse(0)) ^^^^^^^^^^ File "/home/realpython/inverse.py", line 4, in inverse return 1 / number ~~^~~~~~~~ ZeroDivisionError: division by zero Click the link below to download code examples demonstrating the new capabilities of Python 3.11: In addition to learning more about the new features coming to the language, you’ll also get some advice about what to consider before upgrading to the new version. The Python 3 Installation & Setup Guide and How Can You Install a Pre-Release Version of Python? walk you through several options for adding a new version of Python to your system. If you want to try any of the examples in this tutorial, then you’ll need to use Python 3.11.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |