Python is great, but __

I haven’t used Python a lot, but from what I know about it, I consider it one of the good languages. A bonus is that most Python programmers seem pragmatic and humble, which is nice compared to the impression of Ruby community left by some of the more arrogant Ruby folks. But there’s one thing that really irks me about the language, more than the somewhat significant whitespace or some of the syntax quirks:


What the fuck is up with that? I have seen very few pieces of Python code which didn’t contain those double underscores. How was it decided that commonly used names will contain four underscore characters? I doubt that names such as init, main, iter, etc. were considered so precious that the language must not treat them specially. Perhaps in the early days it wasn’t apparent that the magic methods would be used as often as they are? Or maybe it was but the __ didn’t bother enough people? I would find that strange, but then again people get used to everything. Scala makes magic use of the underscore as well, but I’ve gotten used to the few cases where it’s part of names. Most of the time it’s used as a wildcard, and that doesn’t bother me at all.

Do you program in Python regularly? What do you think about the underscores?

5 thoughts on “Python is great, but __

  1. Yeah. Python has been lauded as “executable pseudocode” — with some justification, too. I have to agree that the double underscores are a pretty ugly syntax wart. if __name__ ==”__main__”? Ugh. I’m also not a fan of explicitly passing “self” into every method. Python is a fine language, but not flawless.

  2. Names of the form __name__ have the underscores in order to show that they have special meaning. All the operator overloading methods have leading and trailing underscores. Programmers are warned not to make new methods, variables, etc with leading an trailing underscores because in some future release of Python they may just collide with a name with special meaning. The fact that the underscores are slightly annoying helps ensure people heed the warning, even if they aren’t aware of it. Most people don’t like using underscores that way.

    So when you see those underscores in Python, you know it is something with special meaning.

  3. In addition to what eengbrec said, double underscores also magically create functions that you cannot override or call. In other words, you’d have to type:

    void private final init function() {


    if it were Java. So, in Python, __init__() is private and final but init() or _init() would not be final or private. In general I find private and final methods to be annoying when refactoring or testing but when they are magic hooks into the low level object system (like __init__, __len__, __iter__) then it kinda makes sense.

  4. I agree with you, what the fuck with the “__”, it looks so ugly and some people say it’s elegant. I don’t understand taste of them, if python can remove the “__”, but also the “self”, maybe we can think it’s elegant.

  5. Well this is 6 yeaqrs later and…. What the fuck is up with the underscores. I program in C#, Java, SQL, Javascript and now Python. I just read an article where an underscore can have like 8 different meanings depending on context. I guess the language is so dumbed down this is what the brainiacs are left to wrangle over. I do appreciate all aspects of the language so far. Very easy to learn and use. Was productive in about an hour, but those underscores just suck.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s