Python 3.11 is barely out and already the 3.12 alpha has some improvements for NameError messages. I suspect that these will be backported to 3.11 in time for the next release. On Ideas Python Discussion , Pamela Fox suggested that it might be useful to consider potential missing import when a NameError was raised. Thus, instead of having >>> stream = io.StringIO() Traceback (most recent call…
I am just beginning to learn pandas and am looking to provide some automated help. From what I read, it appears that SettingWithCopyWarning is something that confuse many people. Is the following correct? In [2]: df = pd . DataFrame ([[ 10 , 20 , 30 ], [ 40 , 50. , 60 ]], index = list ( "ab" ), columns = list ( "xyz" )) In [3]: df . loc [ "b" ][ "x" ] = 99 `SettingWithCopyWarning`: A value is…
Just a few minutes ago, @isidentical tweeted that PyPy 3.9 had implemented the new enhanced tracebacks that are going to be part of cPython 3.11 . Of course, I had to reply to show that friendly/friendly-traceback have been able to do the same with all cPython version starting with 3.6.1 . A few hours before this tweet, I had bumped the minor version number of both friendly and friendly-traceback…
friendly_idle is done! I've found a better solution for the remaining issue I had mentioned in the previous blog post. I also found a fix for an "annoyance" mentioned by Raymond Hettinger on Twitter! I could have changed the version to 1.0 ... but decided to wait until I get more feedback from users.
friendly_idle is now available. This is just a quick announcement. Eventually I plan to write a longer blog post explaining how I use import hooks to patch IDLE and to provide seamless support for friend/friendly_traceback. Before I incorporated "partial" support for IDLE within friendly , I had released a package named friendly_idle ... but this is really a much better version. When you launch it…
Beginning programmers are often surprised by floating point arithmetic inaccuracies. If they use Python, many will often write posts saying that Python is "broken" when the see results as follows: >>> 0.1 + 0.2 0.30000000000000004 This particular result is not limited to Python. In fact, it is so common that there exists a site with a name inspired by this example ( 0.30000000000000004.com/ ),…
At EuroSciPy in 2018, Marc Garcia gave a lightning talk which started by pointing out that scientific Python programmers like to alias everything, such as import numpy as np import pandas as pd and suggested that they perhaps would prefer to use emojis, such as import pandas as 🐼 However, Python does not support emojis as code, so the above line cannot be used. A year prior, Thomas A Caswell had…
In the past week, there has been an interesting discussion on Python-ideas about Natural support for units in Python . As I have taught introductory courses in Physics for about 20 of the 30 years of my academic career, I am used to stressing the importance of using units correctly, but had never had the need to explore what kind of support for units was available in Python. I must admit to have…
In my previous post , I mentioned that, unlike IPython, friendly/friendly-traceback included values of relevant objects in a traceback. As I wrote in the update, Alex Hall pointed out that one could get this information by using a verbose mode in IPython. Here is the previous example when using the verbose mode. In (1) I enabled the verbose mode. In (3), we see its effect. (2) is a reminder of the…
UPDATE: Alex Hall pointed out that IPython can display the values of variables in the highlighted sections using %xmode verbose . He also suggested a different highlighting strategy when the problematic code spans multiple lines. I go into more details about these two issues in a future blog post. ====== I'm writing this blog post in the hope that some people will be encouraged to test…
I decided to submit to the the Ideas category of Discuss-Python a proposal which I have summarized as follows: Summary: I propose that a new compile time directive be available to restrict the Python syntax to a strict subset. This would facilitate the teaching of Python to beginners as well as the work of people that write tools intended to help beginners learning Python. Here is a link to that…
Friendly (previously at 0.4.41) and friendly-traceback (previously at 0.4.111) are now at version 0.5. The joint documentation for both projects has not yet been updated. In addition to the many new cases added for which friendly/friendly-traceback can help with, which includes close to 400 test cases, I am very excited to report to three new important features Getting help when a traceback is…
Friendly and Friendly-traceback are now partially available in Spanish thanks to the work of Mrtín René (https://github.com/martinvilu). You can have a look at the Spanish translations in context for SyntaxErrors and for other exceptions . If you are interested in contributing to translations, please join this discussion and have a look at this online collaborative site . Update: Someone just…
There are many custom exception hook that seek to improve upon the standard one from Python. The very first one is Python's cgitb module, but there are many others including, in no particular order, better_exchook , infi.traceback , the traceback submodule of Rich , the different but similarly named rich-traceback , IPython's ultratb module , better-exceptions , stackprinter , pretty-errors ,…
Summary: I have a draft version of a new and arguably better way to display information from friendly for Jupyter labs/notebooks. For now, it only works with the default light theme. The following screen captures illustrate a new way to display the information from friendly inside Jupyter lab/notebooks. Instead of having to type some commands, the user can click on buttons. Initially only the…
Just a quick update ... After over 150 commits, most of which included new traceback cases explained by Friendly-traceback, it is time to go from version 0.3 to 0.4. There are too many changes to mention in this blog post and the documentation needs to be updated. The version change is also to allow me to switch gear and focus on preparing a talk for the next PyConAu . I'm hoping that this can be…
Traceback : Determination of origin; the process of tracing something back to its source . I have been working towards release 0.4 of friendly/friendly_traceback as well as preparing for a talk at the upcoming PyconAU. Those familiar with PyconAU might be interested to note that I plan to include an example related to the flipfloperator . :-) In this preparatory work, I have been revisiting almost…
A few months ago, I mentioned that friendly-traceback had been renamed friendly . As friendly/friendly-traceback evolved, the number of dependencies increased. For some third-party projects that use friendly/friendly-traceback, such as futurecoder and HackInScience , many of these dependencies are simply redundant and represent a performance hit. For this reason, I have split…
Friendly version 0.3 has been released. This version also marks the official name change from the former friendly-traceback. Before I started working on Friendly, I assumed that to do custom exception handling, one simply had to redefine sys.excepthook. However, I since found out that this does not work in many environments, including all those based on IPython (which include Jupyter notebooks).…
Imagine that you wish to run a program that takes a long time to run. Just in case somethings goes wrong, you decide to use friendly-traceback (soon to be renamed...) in interactive mode to run it. This turns out to be a good decision: Time to explore what might be the problem, and where exactly things might have gone wrong. Ooops ... a silly typo. Easy enough to correct: Unfortunately, that did…
tl; dr: I plan to change the name from friendly_traceback to friendly . When I started working on Friendly-traceback, I had a simple goal in mind: Given an error message in a Python traceback , parse it and reformulate it into something easier to understand by beginners and that could be easily translated into languages other than English. A secondary goal was to help users learn how to decipher a…
Real Python is an excellent learning resource for beginning and intermediate Python programmers that want to learn more about various Python related topics. Most of the resources of RealPython are behind a paywall, but there are many articles available for free. One of the free articles, Invalid Syntax in Python: Common Reasons for SyntaxError , is a good overview of possible causes of syntax…
I love Python. A few years after I started using it, I saw someone writing about it and using the phrase "it fits my brain": this is very much how I feel ... at least, for simple straightforward code that doesn't rely on weird metaclass constructs, or even with the added distraction of type annotations. [Yes, type annotations can be extremely useful, but they do not (currently) "fit my brain".] I…
Today, I saw some write up that Friendly-traceback was discussed on the PythonBytes podcast . A comment made during that podcast suggested that it would be useful if an internet search could be performed, perhaps using a function named www. (Another name was mentioned). So, of course I immediately created an issue ... and implemented a first version of this function.
Python is my favourite programming language. Since I discovered it in 2004, programming in Python became my favourite hobby. I've tried to learn a few other languages and have never found one as friendly to beginners as Python. As readers of this blog know, these days I am particularly interested in tracebacks , and I am likely paying more attention than most to Python's improvements in this area:…