I love Python but I understand if someone doesn’t feel it’s a serious language. I don’t agree but they have some good points. That said, not all issues are Python’s fault per se but more about the ecosystem. Also, this post isn’t that actionable; I’ll describe some of the issues in the back of my mind while working on a style guide for our team.

I’ll separate the issues into

  • Real problems — things I still forget or issues in working on a team
  • Nuisances — they confused me while learning or bother me but don’t actually matter now

Things I forget

Which functions take variable-length arguments and which take an iterable? Usually I remember but it’s frustrating when I guess wrong, especially on str.join. I wish Python would coerce my args to the form they want, but that wasn’t even conceivable until recently.

When a subclass overrides a method it’s common to use *args and **kwargs and pass the unconsumed args to the superclass method, which is great for the implementer. But then PyCharm can’t tell me what the args are so I’ve got to keep another documentation tab open. The worst are functions like pandas.DataFrame.plot because the documentation just says they’re passed to matplotlib plotting method but I’m not sure which method they’re talking about.

Forgetting that a function returns a generator and accidentally trying to iterate over it a second time, but it just behaves like it’s empty so the program runs and produces incorrect output. I’d much rather have it crash.

numpy.ndarray doesn’t work with implicit bool test. I forget this one all the time cause it’s more pythonic to write “if mylist” and ndarray usually behaves like a list.

Reverse and reversed: Which one is the function and which one is the argument to sorted? I often get the wrong one for the sorted argument.

map and filter are fantastic but when you’re using a lambda, the iterable blends in with the tail of the lambda at a glance. Although Perl had extra syntax for this, it was easier to visually spot the list compared to the function. If only they were object methods.

When setting up a new computer, I forget that I need to pip install scikit-learn not sklearn.

Working on a team

I haven’t had to share much Python code lately but we’re starting to build up a team so a shared style amongst the team is becoming more important. That said, I believe that code style should be like karma, not dogma.

Single vs double quotes in strings — PEP-8 doesn’t offer guidance, so it seems like people that only do Python do single quote to save typing effort. And if you copy/paste across languages you may prefer double.

String formatting has gone through several revisions in Python history and % formatting still lingers. Python 3.6 added a new style of formatting that’s less verbose with some discussion.

Import style is another one, but in this case PEP-8 offers some guidance. That said, it still remains personal style whether you “import numpy” or “import numpy as np” or “from numpy import median”. Though I’d argue that the latter can lead to confusion for infrequently used functions/classes — imagine seeing “median” in the code somewhere. You don’t know what kinds of arguments are supported and what’s returned, nor the behavior for an empty list.

Might not be real problems but…

There were a number of oddities when transitioning from Java/Perl/C++.

  • Python is usually object-oriented but it’s len(str) not str.len() and hash(x) not x.hash(), and so on.
  • True/False capitalized
  • Virtual environments are fantastic for making sure your dependencies are encapsulated; testing whether the code is easy to setup without the full weight of Docker. But then there’s the Matplotlib bug. Or that time I ran out of hard drive space because I used a separate venv for each project and had some other bad programs installed.
  • Binary dependencies in modules and the Unix-focus of Python can make occasional work on Windows painful, though Anaconda helps tremendously. That said, last time I tried, Theano and TensorFlow were still significant pains on Windows. It probably would’ve been fine if I’d been willing to shell out hundreds for the right version of Visual Studio and/or just pirate it, but I wasn’t.
Show your support

Clapping shows how much you appreciated Keith Trnka’s story.