Those darn strings

It’s long overdue, but I finally added the promised section about “How to deal with strings” to the Python GTK+3 Tutorial. It all started with bug 663610 which got me confused because with PyGObject for Python 2.x you can supply a unicode instance to a method that expects a string, although GTK+ can only deal with UTF-8 encoded 8-bit strings. However, every GTK+ method that returns a string will always be in the form of a str instance. This is not necessarily PyGObject’s fault, it is exceptionally easy to do bad things in Python 2.x when mixing unicode and str (hello UnicodeDecodeError). The lesson hear is that if you use PyGObject for Python 2.x, don’t use unicode and stick to str all the time. If you instead use Python 3.x, you don’t have to worry about this. A more detailed description and a little bit of background can be found in the “How to deal with strings” section of the tutorial. I also want to thank everybody who helped to improve the tutorial as part of Google Code-In 2011. Students wrote sections about Drag and Drop, sub-classing GObject, Gtk.Builder, Gtk.IconView, Gtk.Clipboard, and Gtk.TreeSortable. They all did an outstanding job in improving the tutorial to enable others to learn GTK+ 3 in Python.

Avatar
Sebastian Pölsterl
AI Researcher

My research interests include machine learning for time-to-event analysis, causal inference and biomedical applications.