1. 22
  1.  

  2. 8

    For myself, Python 3 is different enough from Python 2 that it is close enough to learning a new language, and if I’m going to invest that much in a new language, it isn’t going to be Python. It’s just not compelling enough. I use Python for things mostly because I learned it 15 years ago and it is everywhere, not because it’s any good.

    1. 6

      Despite the length of the linked article, I disagree. The most commonly used 99% of the language (besides the print function) are identical. For most of my day-to-day usage the code I write runs simultaneously under Python3 and Python2 with no modification.

      1. 5

        One particular point of pain I’ve experienced is that many of the collection operations return generators now rather than lists, so the following code is the opposite of what my brain wants to happen:

        >>> if filter(lambda _ : False, [1, 2, 3]):
        ...     print("hi")
        ... else:
        ...     print("bye")
        ...
        hi
        

        I can write Python3 code, but I end up having a bunch of list constructor calls everywhere because I don’t know what returns an actual list and what doesn’t. IMO, Python 2 hit the sweet spot for the language. It was good enough to get stuff done but had a clear ceiling on how complicated of a problem you should solve with it. Python 3 is trying to push that ceiling up but it’s not adding anything that I think actually pushes the ceiling up and it is adding some complication I don’t really have any interest in dealing with.

        1. 2

          That’s an interesting point. I think you could try developing a habit of using any or all in such cases, e.g.:

          if any(False for i in [1, 2, 3]):
              print("hi")
          else:
              print("bye")
          

          (Assuming that False is a shortcut for a filtering condition that returns False for all items of the list). Would it help in your case?

          1. 1

            That doesn’t really capture the same thing, in reality it’s something like:

            foo = filter(...)
            if foo:
                # do something with it
            
            1. 1

              Hmm, I’m not sure. The boolean value of a list is True if the list is non-empty and False if it is. So the boolean value of filter(condition, list) is True iff it returns a non-empty list iff at least one element of list satisfies condition. Or do you have something else in mind?

              1. 1

                The code snippet I showed above removes every element from the list but still goes through the True path of the if, this is because filter does not return a list in Python3, unlike Python2, it returns a generator, which is always True.

                EDIT:

                The output in the repl is:

                >>> filter(lambda _ : False, [1, 2, 3])
                <filter object at 0x800799278>
                
        2. 3

          This is the correct answer.

          As someone who works extensively with Python 2 & 3, the differences aren’t that great. At least nothing a 2 minute Google can’t fix.

          At this stage, I see no reason to start a new project in Python 2. Py2 is only used for legacy projects (at work, where upgrading isn’t easy. For my personal projects, I’ve moved to Py3).

          1. 2

            Depends on what you use it for. Especially if you’re making GTK based GUIs, python 3 and its gobject is extremely different from python 2 and its pygtk.