Cognitive Dissonance: Type hinting and linting in Python

At work, the adoption of python 3 was finally moving at warp speed - the end of its support might have had something to do with it. As a result, there was a lot of code to migrate over. One of the things I did during this migration was add type hinting as well as linter checks to the codebase. And I... was not... ready for that! When I first read about type hinting I thought it would be a neat thing to help people new to the language and existing users navigate through code. After all, the language wasn’t becoming statically typed. I figured the hints were, as its name suggested, slight indications. However, combined with static analysis tools, they can actually help you identify bugs and other issues in your code, and I’m all in for that. ...

February 12, 2020 · guidj

Encoding in Python 2 and 3

In this post I an encoding behavior in python 2 and their differences in python 3 If you’re still using python 2, which many folks are, you may run into encoding issues when processing data. Let’s say we have a file called translations.txt that contains translations between English and Mandarin (from the Oxford dictionary): "The book has 500 pages of text.","这本书正文有500页。" "I'll send you a text as soon as I have any news.","我一得到任何消息,就立刻给你发短信。" Now, say we try to read the file in python 2: ...

November 21, 2019 · guidj