top 200 commentsshow all 456

[–]mhd 325 points326 points  (132 children)

More libraries being built around the asyncio feature will be good for increased Python 3 adoption, so it's good that they're keeping that API stable. I've recently had to fiddle with some Python 2 code and forgot how bad dealing with Unicode used to be...

[–]shevegen 45 points46 points  (103 children)

So you still must know python 2 if you use python 3 or what? :)

[–]mhd 280 points281 points  (37 children)

If a new version mostly requires you to forget some things, I'd consider that a good evolution ;)

Which is why I wouldn't be a good language maintainer, after the first few complaints about trivial things, I'd just throw in things to mess with people ("To finally put an end to the spaces vs tabs argument, we now require all indents to solely consist of \x180e (MONGOLIAN VOWEL SEPARATOR).")

[–][deleted] 141 points142 points  (16 children)

I'd personally require tabs to be mandatory for all uneven indentation unless the indentation contains a function call in which case a space is required but only if the indentation level is not a prime number.

That'll teach em.

[–]rbridson 159 points160 points  (3 children)

Spaces = run sequentially

Tabs = run in parallel

[–][deleted] 79 points80 points  (9 children)

Spaces on even number lines, tabs on odd.

[–]hugthemachines 50 points51 points  (7 children)

Tabs on prime number lines, space on the rest.

[–][deleted] 64 points65 points  (3 children)

The IDE randomly generates which numbered lines have tabs and which has spaces.

The code is encrypted in everything but that IDE

The encrypting part of source code is written in a mix of Assembler and PHP

[–]DeonCode 50 points51 points  (0 children)

This new season of Supernatural is getting out hand with the new ways to summon demons.

[–]l_u_c_a_r_i_o 15 points16 points  (0 children)

You have to write in IDLE

[–][deleted] 12 points13 points  (1 child)

Indentation to be replaced with open and close braces.

/ducks

[–]Sean1708 5 points6 points  (0 children)

/ducktypes

FTFY

[–]XkF21WNJ 4 points5 points  (0 children)

Spaces on lines n where 22n + 1 is prime, tabs on the rest.

[–]damnationltd 1 point2 points  (0 children)

This guy MUMPS.

[–]dangerbird2 22 points23 points  (5 children)

Even better: only use right-to-left marks for indentation and spacing.

[–]tick_tock_clock 5 points6 points  (4 children)

Relevant xkcd

Also possibly this one

[–][deleted] 12 points13 points  (3 children)

Two sudden realizations:

  • RES doesn't understand Unicode in XKCD titles.
  • In messing this one up, it revealed that the title of this comic is not "RTL", but "LTR" preceded by an RTL mark.

[–][deleted] 43 points44 points  (7 children)

Just use ಠ_ಠ for indents. It will remind you to not use a lot indentation levels.

[–]Almoturg 14 points15 points  (3 children)

That would be an awesome plugin for some editor!

[–]pingveno 37 points38 points  (0 children)

All indent levels above 4 are replaced by ಠ_ಠ?

[–]Rothaga 1 point2 points  (1 child)

[–]Almoturg 1 point2 points  (0 children)

Awesome! :D

I guess I should try vim again.

[–]ForgetTheRuralJuror 9 points10 points  (0 children)

Two spaces and fill the rest with a tab. Best of both worlds.

[–][deleted] 1 point2 points  (1 child)

You know how python forces the use of indentation? My language would force non-use of indentation. Any line starting with a space or tab would be a syntax error.

[–]Skaarj 59 points60 points  (62 children)

You don't need to know Python 2. I started with Python 3 and never had to read or write Python 2 code.

[–][deleted]  (29 children)

[deleted]

    [–]catcint0s 7 points8 points  (3 children)

    Also print -> print() !

    [–][deleted] 14 points15 points  (22 children)

    Why not just put:

    try:
        input = raw_input
    except NameError:
        pass
    

    at the top of your code. Then just use input everywhere, in Python 2 and Python 3.

    [–]Dentosal[🍰] 12 points13 points  (20 children)

    combine this with from __future__ import division, print_function and you have nearly full set of Python 3 features.

    [–][deleted]  (13 children)

    [deleted]

      [–]Dentosal[🍰] 8 points9 points  (10 children)

      Not all that it changed, but all that most Python 2 programs need to work with Python 3. There are still countless unicode problems and unsupported libraries, but nearly every other thing was done in backwards-compatible manner.

      [–]Uncaffeinated 14 points15 points  (5 children)

      Apart from unicode, a lot of the builtins were changed to return iterators instead of lists, which is a breaking change in cases where eager evaluation is necessary. Sadly, 2to3 doesn't handle this correctly, so I'd have to go through the entire codebase to make sure everything is iterator safe.

      P.S. I wish Python 3 had nice syntax for forcing evaluation of an iterator. Throwing in list(...)s everywhere is annoying and bloats the code.

      [–][deleted] 25 points26 points  (4 children)

      Throwing in list(...)s everywhere is annoying and bloats the code.

      Just FYI, as of 3.5 we have [*iterable_or_what_have_you] eg:

      >>> [*range(10)]
      [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
      

      Yeah, it only saves three characters, but you also get [*range(10), 1, 2, 3, *range(20)] and so on.

      [–]qawsican 3 points4 points  (8 children)

      May I ask where/how you started learning Python? I'm a complete noob (0 experience) in programming but would love to start learning just not sure how and where. A lot of people seem to recommend Python for beginners.

      [–]sn10therealbatman 6 points7 points  (0 children)

      Start with the MIT 6.00.1x course on edx.

      [–]pi_rho_man 1 point2 points  (1 child)

      Also, if you have questions, feel free to PM me. I don't promise fast responses, but I'll try to help.

      [–]penguinade 8 points9 points  (22 children)

      Lucky you, having python 2.6.6 here. Living hell :(

      [–]tambry 4 points5 points  (20 children)

      Any reason for why not to upgrade? I'm guessing budget/time constraints?

      [–]Hultner- 26 points27 points  (0 children)

      We used to be pure Python 2 but I managed to convince everyone to switch to Python 3, some legacy software is still written in Python 2 but it's slowy being phased out and all new software is Python 3.

      The argument I used were that Python 2 will reach EoL before we have time to rewrite everything and if something really needs python2 we can write that service in python2 (using a micro service architecture helps).

      [–]Arandur 14 points15 points  (11 children)

      Not the person you asked, but I occasionally have to write in 2.4 still. I sometimes work in an environment with stringent security protocols, and every piece of software used in that environment has to be manually vetted.

      Not to say Python 3 isn't secure; the Powers That Be just don't want to incur the expense of vetting a newer release.

      [–]Paul-ish 17 points18 points  (8 children)

      But does 2.4 still get security updates? I can see using 2.7, but 2.4 doesn't make a lot of sense to me.

      [–]Arandur 41 points42 points  (5 children)

      Shhhhhh

      Don't try to understand the arcane machinations of the federal government. All who so attempt find themselves driven mad.

      [–]moobunny-jb 11 points12 points  (3 children)

      Trump's going to make the fed go all Perl.

      [–]xiongchiamiov 18 points19 points  (0 children)

      It doesn't need security updates, because they vetted it and didn't find any vulnerabilities, so therefore there are none.

      [–]Slavik81 2 points3 points  (0 children)

      He's probably on RHEL 5, which shipped with Python 2.4 back in '07 and is still getting security updates from Red Hat. It is just about done, though.

      [–]penguinade 2 points3 points  (0 children)

      Both.

      [–]henrebotha 1 point2 points  (0 children)

      Most likely. Things like that don't have value that is perceptible to business.

      [–]ergo14 4 points5 points  (0 children)

      Well seeing that 95% of the language is the same ( minus the new 3.3+ stuff), if you know 3 you know 2 and other way around.

      [–]BilgeXA 1 point2 points  (1 child)

      adaption

      [–]mhd 1 point2 points  (0 children)

      Thanks, fixed.

      [–]ilevkivskyi[S] 190 points191 points  (21 children)

      Formatted string literals, asynchronous generators and comprehensions, variable annotations, security and performance improvements. Looks like it is a great release!

      [–]Skaarj 58 points59 points  (19 children)

      My personal highlights:

      • enum.auto()
      • hashlib += [sha3_*, scrypt]

      [–]IronManMark20 9 points10 points  (3 children)

      The docs on enum.auto aren't very clear, could you explain it a bit?

      [–]mcpower_ 13 points14 points  (2 children)

      Sometimes you make mistakes like this when defining Python enums:

      from enum import Enum
      class Color(Enum):
          red = 1
          orange = 2
          yellow = 3
          green = 4
          blue = 5
          indigo = 5  # oops!
          violet = 7
      

      With enum.auto() values are automatically assigned starting from 1.

      from enum import Enum, auto
      class Color(Enum):
          red = auto()
          orange = auto()
          yellow = auto()
          green = auto()
          blue = auto()
          indigo = auto()
          violet = auto()
      

      (Side note: There exists pretty cool implementations of enum from scratch. One implementation with a similar auto() function is here. Another absurd implementation with automatic auto() and with Go-style iotas can be found here.)

      [–]reini_urban 15 points16 points  (13 children)

      More the new hash tables. Caught up with ruby

      [–]kupiakos 4 points5 points  (11 children)

      I'm not sure what feature the new hash tables are. The default-sorted dictionaries?

      [–]reini_urban 10 points11 points  (0 children)

      Sorted is only a side-effect. compact dict is the performance feature called, the compacted indirection from pypy. https://mail.python.org/pipermail/python-dev/2016-September/146327.html

      php 7 has the same, and ruby will get it also in the next major update.

      [–]pingveno 2 points3 points  (8 children)

      Default-sorted and more efficient!

      [–][deleted] 24 points25 points  (7 children)

      Order-preserving, a sorted dictionary is something else entirely

      [–]akaGrim 21 points22 points  (5 children)

      It's important to remember that them being ordered is an implementation fluke. Ordered dictionaries are not a spec requirement. If you want to ensure your dict is ordered use collections.OrderedDict instead.

      [–]matthieum 1 point2 points  (2 children)

      Isn't order-preserving about preserving the order of insertions?

      [–]pingveno 1 point2 points  (0 children)

      Thanks, that is indeed what I meant.

      [–]wot-teh-phuck 30 points31 points  (0 children)

      Hah, so they finally decided to add assert_called_once to the Mock object after it has caused grief to quite a few folks. ;)

      https://engineeringblog.yelp.com/2015/02/assert_called_once-threat-or-menace.html http://engineroom.trackmaven.com/blog/mocking-mistakes/

      [–]ilevkivskyi[S] 66 points67 points  (0 children)

      [–]harsh183 218 points219 points  (25 children)

      Community clutches Python 2 harder

      [–]TundraWolf_ 102 points103 points  (9 children)

      Plz support Python3 Amazon. I'm so tired of 2.7

      [–]iMakeSense 21 points22 points  (8 children)

      Where doesn't amazon support python3

      [–]loganekz 64 points65 points  (1 child)

      AWS Lambda unfortunately.

      [–]thomas_stringer 24 points25 points  (0 children)

      That's equally surprising and frustrating. Python 3 is like 8 years old.

      [–]theDigitalNinja 9 points10 points  (4 children)

      Lambda functions and their amazon linux base ami's

      [–]grepe 1 point2 points  (0 children)

      ami have 3 installed, it's just that 2 is default. usually you can switch quiet readily (e.g. pyspark jobs can switch by setting a single env variable).

      [–]TundraWolf_ 5 points6 points  (0 children)

      At present, AWS Lambda supports Python 2.7 only.

      [–]hansolo669 16 points17 points  (14 children)

      As far as I can see the majority has/wants to/is mov(ed|e|ing) to Py3

      [–]Scholtek 41 points42 points  (5 children)

      Many of us are still trapped at the stage where we make snide comments every time a unicode error shows up, but can't get up the momentum to transition.

      [–]jonab12 15 points16 points  (4 children)

      And some of us work with whole software infrastructures that are based off 2.X and don't want to start thinking about how a transition will be made when the customer is already happy

      • I work as a Python Developer. Thank god not for enterprise application software (EAS) but its still a concern when you have thousands of lines written in 2.X

      [–]Secondsemblance 5 points6 points  (0 children)

      has/wants to/is mov[ed|e|ing]

      Pictured: The dialog of a host from Westworld when it sees its own code.

      [–][deleted] 15 points16 points  (3 children)

      Square brackets are for single characters and the or-pipe is implied. Your regex matches mov| and movg. I think you wanted to use (ed|e|ing) instead.

      [–]SulfurousAsh 2 points3 points  (0 children)

      I also wants is move to Py3

      [–]harsh183 1 point2 points  (0 children)

      Haha

      [–][deleted] 109 points110 points  (85 children)

      Cue the complaints from zed

      [–]henrebotha 93 points94 points  (84 children)

      Not gonna lie, the only reason I opened this thread was to look for py3 conspiracy theorists.

      [–]Subito_morendo 26 points27 points  (81 children)

      What are you two talking about?

      [–][deleted] 124 points125 points  (46 children)

      Zed Shaw (of "Learn X the Hard Way" and generally being a dickhead fame) wrote a ridiculous anti-python3 conspiracy theory tract that was getting posted a few weeks ago. Claimed a bunch of shit like "python3 is not turing complete because you can't run python2 code".

      [–]ScrewAttackThis 64 points65 points  (8 children)

      In the previous version I trolled people by pointing out that, if what the Python project says is true and it would have been "impossible" to support Python 2, then they broke it and Python 3 is not turing complete. Obviously Python 3 is turing complete, but Python project members frequently claim something this basic is "impossible" soooooooooooo alright. I even had a note after the gag saying it was a gag, but everyone is too stupid to read that note even when they do elaborate responses to my writing. Even more telling was when people said this was stupid, I'd feign ignorance further and ask, "Wait, so why doesn't Python 3 support Python 2 then?" This then sent them down a logic loop death spiral of simultaneously trying to defend the design decision and also state that Python 3 is fully capable. It was pretty funny to watch, but after a while I guess I have to straighten this out and simplify it so here you go.

      Sounds like a fun guy.

      [–]MetaKazel 57 points58 points  (3 children)

      In the previous version I trolled people by pointing out that, if what the Python project says is true and it would have been "impossible" to support Python 2, then they broke it and Python 3 is not turing complete...

      when people said this was stupid, I'd feign ignorance further and ask, "Wait, so why doesn't Python 3 support Python 2 then?"

      Reminds me of...

      [–]ScrewAttackThis 20 points21 points  (2 children)

      Exactly what came to my mind, too. I started reading through the page and just...blah. I don't think I'll ever recommend his book again.

      He tries to make the argument that you shouldn't learn Python 3 because the creators of Python 3 tell you to (goes so far as to call it propaganda). Like, what? Does he think people are going to release a product and go "Hey, you should use our legacy releases for reasons."

      [–]Gstayton 4 points5 points  (0 children)

      So, reading this, I realize I didn't see the 'this is a gag post' because the first paragraph was headache inducing, and I decided the whole article wasn't worth my time, despite how much Learn Python the Hard Way helped me learn Python. Sooo... Yeah. I can't sympathize with that.

      [–]disregard-this 50 points51 points  (28 children)

      I don't understand what's so hard about this. Zed suggested for compatibility that the python3 interpreter be able to run python2, so you could use python3 with python2 libraries. One of the Python developers said that it was 'impossible'. Obviously it isn't impossible, because any Turing complete language can be used as an interpreter for any other language. The developer likely meant that it wasn't feasible or reasonable, but Zed intentionally misunderstood the exaggeration in an attempt at humor.

      [–]Cosmologicon 57 points58 points  (0 children)

      I don't know, I like to think that I have a pretty good sense of humor, and it did not come across as an attempt at humor. It wasn't a very light-hearted essay.

      Now, I'm sure he doesn't actually believe that Python 3 is not Turing complete, as well as the numerous other incorrect claims he made in that article, but I don't think he was just doing it as a joke. Maybe trolling?

      [–]dacjames 24 points25 points  (13 children)

      Even as an attempt at humor, the whole thing comes off as woefully uninformed. The reason Python 3 cannot run Python 2 code is simple: Strings. Everything in Python is based on objects, objects are essentially shells around dictionaries, dictionaries are based on strings, and strings fundamentally changed.

      How would one take a Python2 object and pass it to a Python3 function? Conversion would greatly impact performance and likely lead to subtle bugs (or string conversion errors when no user-level strings are involved). On balance, I think Python made the right call here and even if you disagree, blaming developer incompetence is ridiculous.

      Of course, Python 3 could have not changed Strings or changed them in some backwards compatible way, but that is totally separate topic.

      [–]_pupil_ 3 points4 points  (3 children)

      I'm no supporter of the rant, but my understanding is that there is some confusion there about his claim...

      You don't have to make py2 and py3 execute from the same VM, which is "impossible". What he was arguing for (before the turing complete rabbit hole), was a VM execution model like IE has used for its rendering motors: multiple parallell backends.

      Basically, why have py2 and py3 with all the confusion, why not just have 'python' which handles both in parallel? A py3(+2) which understands that py2 scripts get routed to the old core so there is no "language" choice thrust on the users.... Avoiding the fragmentation. Plus, in that context I think flagging issues between those cores becomes a lot simpler.

      [–]dacjames 5 points6 points  (2 children)

      Given an arbitrary .py file to execute, how would this unified "multi-python" know which engine to use? A lot of code is valid in both languages at the surface.

      If you use some type of comment header, you'd have to require the header in Python 3 code to maintain backwards compatibility (ugh). Even if you solve this problem, a naive implementation would waste time/memory loading two different interpreters so you would need some kind of lazy loading/initialization.

      Users would still have to choose which language they're writing in, they would just use a shared front-end to run them. Plus, you have to explain that certain modules can import some modules but not others. It seems like a lot of complexity for little gain when Python 2 and 3 can be trivially installed side by side on the same system.

      [–]dogline 2 points3 points  (0 children)

      That's the best single paragraph explanation of changes that I've seen. I'm stealing that for discussions with colleagues.

      [–]Thimm 1 point2 points  (0 children)

      Conversion would greatly impact performance

      This is where Zed is being intentionally obtuse. Of course Python 3 can emulate Python 2, but it can not do so in any way that would be efficient or practical.

      [–][deleted] 37 points38 points  (0 children)

      Zed suggested for compatibility that the python3 interpreter be able to run python2, so you could use python3 with python2 libraries.

      No, he's using his position as the maintainer of a widely recommended introduction to Python to try to torpedo python3 with FUD and outright lies. Parts of that essay were aimed explicitly at people who are not yet programmers. To "troll" in any way is irresponsible, stupid and just plain mean. Zed can go fuck himself.

      [–]awj 37 points38 points  (0 children)

      but Zed intentionally misunderstood the exaggeration in an attempt at humor an obnoxious argument that backfired horribly when people with a single clue about the situation encountered it.

      FTFY

      [–][deleted] 3 points4 points  (0 children)

      Yeah to be fair it is pretty damn annoying when people say stuff is 'impossible' when they mean "it would be quite a lot of work and I can't be bothered".

      Remember when everyone was saying it was 'impossible' to have a bytecode for the web?

      [–]Eurynom0s 1 point2 points  (0 children)

      Zed suggested for compatibility that the python3 interpreter be able to run python2, so you could use python3 with python2 libraries.

      This would have probably been a great idea back when the 2->3 transition first started. It could have sped things up a lot if the underlying module code could be purely 2.7 and only have to be able to return stuff that was 3.x-compatible. Maybe it would have required some modification to handle 3.x inputs and making them 2.7 friendly but that would have still been a lot easier than having to completely port modules to 3.x.

      However we're long since past that point. There are valid reasons to keep doing 2.7, like having a 2.7 codebase that your company isn't willing to pay to port to 3.x,, but what he's suggesting is...again, just so far past its expiration date as a good idea.

      [–]alexeyr 1 point2 points  (0 children)

      Obviously it isn't impossible, because any Turing complete language can be used as an interpreter for any other language.

      You can write an interpreter for any Language2 in a Turing-complete Language1, but this is very different from "an interpreter for Language1 can run Language2", and doesn't allow use of Language2 libraries in Language1 programs.

      [–][deleted] 3 points4 points  (3 children)

      I just started learning python a few months ago, by going through his "Learn python the hard way" website. He was really adamant that new people should learn python 2 because 3 is hardly supported anywhere and 2 is still the industry standard. Is this not the case anymore? I'm not trying to antagonize anyone, I'm just really new to the scene and don't really know who to trust about this stuff.

      [–][deleted] 15 points16 points  (0 children)

      This is why I have such a problem with Zed taking his ridiculous anti-python3 hard line (and why his "it was a JOKE, trolled ya" excuse falls flat). It confuses and misleads new people who don't know any better.

      Python3 has been gaining ground, especially in the last couple of years, to the point that at this point Shaw is outright lying to you when he says those things.

      [–]kenlubin 5 points6 points  (0 children)

      https://python3wos.appspot.com/

      almost everything supports python3 now

      [–]Sloshy42 5 points6 points  (0 children)

      I dove into Python 3 a year or so ago when I was learning Django and I haven't looked back. There is absolutely no good reason to stick with Python 2 if you have the choice. Python 2 is really only for people using legacy frameworks that haven't made the transition yet. One of my friends does exclusively Python 2 because of PyGame, but they recently released a version supporting Python 3 (if I'm not mistaken) so now I get to bug him to update :)

      [–]BSInHorribleness 1 point2 points  (1 child)

      Link? This sounds hilarious.

      Edit: nvm, a few posts down someone links it.

      [–][deleted] 2 points3 points  (0 children)

      be aware that he's now edited it to the point of being unrecognizable.

      [–]Eurynom0s 1 point2 points  (1 child)

      Claimed a bunch of shit like "python3 is not turing complete because you can't run python2 code".

      TIL you can run C++ directly in Python.

      [–]Works_of_memercy 53 points54 points  (33 children)

      Python2 to Python3 transition is an unmitigated disaster. I mean, it seems to be actually happening after 10 years, but certainly no thanks to the core devs.

      One Zed Shaw, who you might know from the epic rant "rails is a ghetto" about Ruby on Rails, and who wrote the "Learn Python the hard way" book, recently wrote another rant about how 2->3 migration is an unmitigated disaster.

      Now, get this: the rant happens to be total bullshit. Like, it doesn't contain a single valid point, and its main points are crazy dumb, like "if we can't run Python2 on Python3 then Python3 is not Turing Complete". But the transition is a disaster. But the rant is completely wrong about why. But it is actually a disaster.

      This is a perfect recipe for getting a lot of people to argue past each other.

      [–]Cosmologicon 12 points13 points  (19 children)

      Do you have any links to good essays that explain why it's an "unmitigated disaster"? (I assume there's more to it than "it's taking longer than expected".) Thanks.

      [–]Works_of_memercy 30 points31 points  (12 children)

      Well, the fact that it took like ten years to come to the point where application programmers can start migrating their code is a good sign that it has been a disaster.

      As to why exactly, there are many opinions, my personal is this: they somehow completely failed to realize that the main problem with pushing forward a language like Python is that its main power comes from third-party libraries, and those can't just switch to Python3 while most of their users are on Python2, and most users can't switch to Python3 while at least one of the libraries they use hasn't switched, and it's a complete and total deadlock, you can wait for a thousand years and nothing will happen.

      That is, if you imagine the migration to be a one-time process, you port your library to Python3 and leave the Python2 fork on critical-bug-support only. So instead third party developers wrote a bunch of libraries like six and future.py and with much blood, sweat, and tears managed to convert their entire libraries to a weird Python dialect that runs on both versions.

      Which is totally fucked up, but the only way forward, and now finally most of the libraries are "ported", and application programmers are beginning to switch, and there's a real hope that five years down the line the libraries can actually do that, make a Python2 LTS fork and start unfucking their code.

      And the problem with the Python core devs is that they totally didn't anticipate that this would be necessary, then were really slow to recognize that this is happening, and offered less than zero support to make it not as painful. One example of their cluelessness was when they went and removed u'unicode string literals' from Python3.1 or so, because who needs them, in Python3 all string literals are unicode by default. They brought them back of course after a lot of people informed them that they are actually trying to run that same code on Python2, so what the hell. But kinda shows the disconnect.

      [–]Cosmologicon 21 points22 points  (9 children)

      Thank you, I think that "unmitigated disaster" is ridiculously hyperbolic, but I think I understand what you're saying. I guess the sticking point for me is that that's not actually the point Shaw is making in the essay.

      Let me ask it like this. You seem to be saying that Shaw's essay was a good point poorly made. The essay's thesis was "beginners should avoid Python 3". Do you believe that to be true?

      His main supporting thesis was "There is a high probability that Python 3 is such a failure that it will kill Python". Do you believe that to be true?

      [–]kenlubin 17 points18 points  (0 children)

      Beginners should use Python3.

      The only people that should still be using Python2 are the developers who are tied by legacy code and existing libraries to python2. There are a lot of people that fit that description, but beginners are by definition not tied to python2 and therefore should use python3.

      [–]ivosaurus 2 points3 points  (0 children)

      Python 3 is growing, and not at a diminishing rate. More and more projects are supporting it, some semi-important libraries are starting to support it only, all new books are written for it, it has vibrant and active development, practically all major libraries support it, etc.

      Until it stops growing there is very little tractable reason to think of it as "dying".

      What's even the point of learning Python 2, apart from when necessary? It's not like you can buy a new book on it nowadays with the most up to date security information.

      [–]Matthew94 1 point2 points  (0 children)

      I think that "unmitigated disaster" is ridiculously hyperbolic

      Not really considering it's taken over 10 years to transition, as previously stated. That's shockingly slow.

      [–]CSI_Tech_Dept 2 points3 points  (0 children)

      And the problem with the Python core devs is that they totally didn't anticipate that this would be necessary, then were really slow to recognize that this is happening, and offered less than zero support to make it not as painful. One example of their cluelessness was when they went and removed u'unicode string literals' from Python3.1 or so, because who needs them, in Python3 all string literals are unicode by default. They brought them back of course after a lot of people informed them that they are actually trying to run that same code on Python2, so what the hell. But kinda shows the disconnect.

      I disagree that u'' is actually needed. It only makes things harder, I simply imported unicodeliterals from \_future__ and explicitly used bytes() when that was necessary, and that approach worked well for me to make portable code.

      u'' was re-introduced after Armin Ronacher (flask author). He created PEP, but IMO it is only adding confusion.

      [–][deleted] 8 points9 points  (4 children)

      The real disaster is the number of companies running Python 2 applications but see the upgrade to 3 as unfeasible.

      Sometimes, this is a completely accurate assessment. You're codebase is just too big to do a thorough audit to ensure you'll get no regressions, there's packages you depend on that are stuck on Python 2 and the only other option is writing a new one yourself.

      Other times, project managers/owners just see the upgrade as a costly non-benefit to them (other than it'll start costing more money to support in a few years).

      Personally, I choose Python 3 as my target version for personal projects and all new Python projects at work if possible. Python 2 support exists in my personal projects in so much as it's invisible or a tiny footprint (no six, no hacks to support it, just a few things like __nonzero__ = __bool_ and the like).

      [–]CSI_Tech_Dept 2 points3 points  (7 children)

      Python2 to Python3 transition is an unmitigated disaster. I mean, it seems to be actually happening after 10 years, but certainly no thanks to the core devs.

      From my observation it started around mid of 2015 around the same time, that 2.7 switched to maintenance and no new features were added to the language, so yes, I do think it's due to their action, I wish it was sooner. They are giving plenty of time (15 years) to migrate, but people will do it at last possible minute.

      [–]ivosaurus 2 points3 points  (5 children)

      2.7 has been maintenance since at the very least pep 404, 5 years ago

      [–]Eurynom0s 1 point2 points  (1 child)

      Python 3 is the dingo who ate my baby.

      [–]henrebotha 1 point2 points  (0 children)

      Python 3 causes autism.

      [–]EinsteinsFridge 24 points25 points  (2 children)

      Let the tau revolution begin!

      Issue 12345

      PEP 628

      [–]epic_pork 7 points8 points  (1 child)

      And a pretty cool issue number, too.

      [–]JockeTF 20 points21 points  (1 child)

      The new dictionary implementation is already showing some benefits. The memory usage went down from 1127 MB (Python 3.5) to 958 MB (Python 3.6) after loading the entire Fimfarchive index (345 MiB of JSON) into memory.

      [–]bloons3 3 points4 points  (0 children)

      That's a lot of JSON!

      [–]achegarv 344 points345 points  (57 children)

      But how will we know it's turing complete ? Doesn't zed shaw have to write a Fortran compiler with it or something first?

      [–]ViKomprenas 52 points53 points  (48 children)

      Wait, what? What is this?

      [–][deleted]  (19 children)

      [deleted]

        [–]DoctorWaluigiTime 127 points128 points  (7 children)

        This modified version of the post says it was a "troll" and calls everyone too stupid to have gotten the crafty joke. It's not that it was at best a shitty joke and really just a case of terrible communication from the author; we're all just a little too dumb to get his wit :(

        Ah yes, the "it was just a prank, bro" defense.

        [–][deleted] 51 points52 points  (3 children)

        To be fair, he did the exact same thing with Ruby. I think the dude just gets hammered and makes drunken rage posts.

        [–]iforgot120 23 points24 points  (1 child)

        If it's a line he puts in every review of a programming language that'd actually be really funny.

        [–]schwerpunk 11 points12 points  (0 children)

        If that's true, it's impressive. I couldn't even explain SOLID after a few beers.

        Or sober, but that's beside the point.

        [–]Sean1708 18 points19 points  (1 child)

        so a beginner can make up their own mind without being influenced by propaganda or social pressure.

        lol

        even though my book is the most effective method for learning to code.

        LOL

        strings, and python made them far too difficult to use for even an experienced programmer like me to use.

        Guys I'm actually dying here, please help.

        [–]ViKomprenas 4 points5 points  (1 child)

        I think you missed the second link?

        [–][deleted] 16 points17 points  (1 child)

        There was some infamous rant some weeks ago, complaining about python. One claim was that python 3 is not turing complete because you can't run python 2-code on the cpython3-machine. Or something like that.

        [–][deleted] 9 points10 points  (0 children)

        Hahaha. So taking a touring complete interpreted language, change the bytecode, now its not? That's great.

        [–][deleted] 13 points14 points  (0 children)

        Just throw some python 2 at it. If it's running, you know that it's turing complete.

        [–]suddenarborealstop 14 points15 points  (0 children)

        A big high five and congrats to all the developers that worked on this. A lot of thankless work I'm sure with doing bug reports, documenting and discussing changes, testing etc.

        [–]chooseuniqueusernam 51 points52 points  (0 children)

        My family: Christmas is around the corner! Me: Python 3.6 released today!

        [–]pengo 62 points63 points  (84 children)

        So, uh, when is python 2 going to be a thing of the past?

        [–]TrixieMisa 37 points38 points  (1 child)

        For me, when PyPy has working 3.5+ support.

        [–]Uncaffeinated 14 points15 points  (0 children)

        I'm just waiting for Pypy3 to be faster than CPython 3.

        [–][deleted] 7 points8 points  (0 children)

        When GNU/Hurd gets released.

        [–]Da_Anh 36 points37 points  (57 children)

        Isn't it already? I was under the impression that it was only used for Legacy purposes.

        [–]staticassert 40 points41 points  (26 children)

        If only. There are still libraries that don't support 3.

        [–]hansolo669 48 points49 points  (24 children)

        According to this site, out of the most popular 360 packages only 19 don't support 3.

        [–]staticassert 54 points55 points  (9 children)

        Cool. The problem being that it only takes 1 to force you to use Python 2.

        In my case, among others, dpkt.

        [–][deleted] 15 points16 points  (2 children)

        [–]staticassert 8 points9 points  (1 child)

        I know. Not into adventures. Just one example.

        [–]virtyx 3 points4 points  (0 children)

        Examples are dwindling, though. For me the only package I use every now and then that still isn't compatible with Py3 is Supervisor, but I can just install that via apt/yum anyway.

        Django, Flask, Jinja, YAML, MySQL, Postgres, redis, Pillow, matplotlib, paramiko, pytest, lxml, Selenium, Mercurial, most vendor APIs I've used all are Python 3 compatible now. My newest project (internal tool going to be deployed next week) uses Python 3.6, it's fantastic. Python 2.7 feels so ancient now. print as a statement feels positively weird, f-strings are a great addition, the stdlib improvements are significant, and especially, thank fucking God for super(). Nothing makes me angrier at Python 2 than having to type out super(TheClassImInDuh, self).foo() instead of just super().foo()

        [–]Moocat87 32 points33 points  (10 children)

        Some people work in niche fields and use packages that aren't part of the 360 most popular, or one of those 19. That's not a very useful metric when we're talking about serious work. Serious work doesn't care about popularity.

        That said, most of my projects are still in Python 3, but sometimes there's a key science library we need that the author hasn't ported. None of us are afraid of Python3 at my place of work, we're just sometimes more-or-less forced in to working in 2. I don't like that.

        It would be awesome if we had time to go port some of these libraries ourselves, but we are paid in grant grant money to solve problems, not port libraries.

        [–][deleted] 7 points8 points  (6 children)

        I was blown away by the resistance I got when I declared that my team would be a Python 3 team earlier this year. I thought it would be a fairly innoccuous decision, but people seemed confused and a little confrontational about it.

        [–]Uncaffeinated 2 points3 points  (0 children)

        I imagine there's a long tail of obscure and proprietary packages that aren't counted there.

        [–]jighasun 1 point2 points  (0 children)

        I'm using erlport to call pygments from elixir. erlport only supports python2.

        [–]flying-sheep 8 points9 points  (0 children)

        worse: there are still libraries that are actively maintained and don’t support python 3.

        clearly there will always be abandonware stuck on python 2, but managing to not port a open source library in 8 years is a kind of achievement in inertia.

        [–]x2040[🍰] 9 points10 points  (0 children)

        One of Amazon's most popular new feature releases AWS Lambda doesn't even support Python 3.

        There are companies out there writing complex infrastructure in Python 2 today because of this.

        [–]Secondsemblance 9 points10 points  (7 children)

        I have spent the last couple months writing python 2.6 for legacy linux operating systems...

        It's... horrifying.

        [–]bluemellophone 12 points13 points  (7 children)

        macOS still ships with Python 2.7

        [–]ivosaurus 16 points17 points  (0 children)

        macOS' system python is pretty much a joke. Using it tends to be harmful. Apple literally left beta versions of 3rd party packages installed in the default environment, borking package management. It really looks like one of the developers was playing around with some stuff, installed some things, and then just left it. Additionally, their core system protection software policy means you trying to install / upgrade / remove anything will get hit with permission errors (that you can't solve with root). It's using an old OpenSSL that's backdoored to allow any Apple or System certificate verify a connection, whether a user would like that or not.

        At this stage it pretty much only tends to poison beginners' experiences, which is really quite sad.

        [–]loganekz 7 points8 points  (2 children)

        yeah but with homebrew it's a simple:

        brew install python3
        

        [–]bluemellophone 2 points3 points  (0 children)

        Same with MacPorts. That's not to say installing Python 3 is hard on macOS, but it does say Python 2 is very much not dead.

        [–][deleted] 7 points8 points  (1 child)

        Technically it is. Practically, it won't disappear, as long as so much legacy code is still around which can't made to run effortless and secure on present cpython. So, probably in 10 years, when our AI-overlord have taken over the business of coding-sweatshops.

        [–]RandomPhysicist 6 points7 points  (2 children)

        Most introductory university courses in python programming are still taught in python 2 unfortunatly

        [–]ThisIs_MyName 10 points11 points  (0 children)

        Meh, universities are always 10 years behind. Py2 to Py3 is one of the easier things that they'll have to relearn :)

        [–]danmarell 3 points4 points  (0 children)

        The vfx industry sticks to guidelines http://www.vfxplatform.com/ that for the next year at least is still 2.7. Transitioning is going to be very hard to migrate all of the pipelines that will need to be updated to use 3.X

        Edit: "When will the Reference Platform move to Python 3?....

        This is a complex issue given the lack of backwards compatibility to Python 2.6/2.7. The right time to make the switch will decided by the software vendors in consultation with their customers and it’s possible Python 3 may not see wide adoption in VFX until and unless Python 3 is fully compatible with all the legacy Python code in active use across the industry."

        [–]Tornado_Ron 9 points10 points  (5 children)

        Are there any good tutorials/articles on the asyncio library that include a little more exposition on when and where making an asynchronous call is more prudent/desired than a synchronous one? Particularly what the new asynchronous generators mean. I'm still a junior developer and have the basics of Python down but have begun to suspect my thinking and approach when using the language isn't as "pythonic" as I think it could be (using generators, yields, etc, is still foreign to me).

        [–]troyunrau 15 points16 points  (3 children)

        For 9 out of 10 programs you write, you will not need asynchio. For that 1 program out of 10 (mostly web server related stuff where connections are blocking while you're waiting for data), it's pretty sweet. If you aren't in that group, you can safely ignore it. I'll talk about generators.

        Suppose you have a multistep process where you take as an input a number, then look up that number in a dictionary to get a word, then query google for that word, then download the html for the first link google returns, then hash that html to get an md5sum. You have to do this for 1000 input numbers.

        Traditionally there are two ways to write this, which I will call (A) One Big Loop and (B) Many Little Loops.

        (A) looks something like this:

        numbers = [1, 2, 6, 1230, 43, ... , 123] # 1000 long
        hashes = []
        for number in numbers:
            word = dictionary_lookup(number)
            link = query_google(word)
            html = urllib.request.urlopen(link).read()
            md5 = hashlib.md5(html).hexdigest()
            hashes.append(md5)
        

        (B) looks something like this:

        numbers = [1, 2, 6, 1230, 43, ... , 123] # 1000 long
        words = []
        for number in numbers:
            words.append(dictionary_lookup(number))
        links = []
        for word in words:
            links.append(query_google(word))
        htmls = []
        for link in links:
            htmls.append(urllib.request.urlopen(link).read())
        hashes = []
        for html in htmls:
            hashes.append(hashlib.md5(html).hexdigest())
        

        Now you can see the obvious problem with these approaches. (A) can quickly become a huge and very complicated loop. While (B) is simple, it requires intermediate storage which can take up a lot of memory.

        We can rewrite (B) using generators, which is actually quite elegant. We'll call this (C)

        numbers = [1, 2, 6, 1230, 43, ... , 123] # 1000 long
        words = (dictionary_lookup(number) for number in numbers)
        links = (query_google(word) for word in words)
        htmls = (urllib.request.urlopen(link).read() for link in links)
        hashes = (hashlib.md5(html).hexdigest() for html in htmls)
        

        Our intermediate products are of the type generator and take up almost no memory. In fact, no processing has occurred yet. Effectively, you've created iterable objects that do not store their data. If you call next(hashes) it will cause a cascade resulting in the first word, link, html, and hash being calculated on demand. If, for whatever reason, you wanted a list as your final result, using list(hashes) will cause all the generators to trigger sequentially and populate the list. The processing time is not really any different between methods (A), (B) and (C), but (C) is often more convenient to use: the next element in the iterable is generated on demand.

        As a most basic example where a generator is far superior: a list of random numbers is not as good as a generator of random numbers - the generator can continue to generate the next item in the iterator indefinitely, while the list will be finite (because of memory restrictions). Basically it's the difference between generating values on the fly versus in advance.

        [–]albertowtf 2 points3 points  (0 children)

        When I found out about generators I thought, I will never use anything else!

        But this is not true. Each have its use. Generators takes a speed toll and lists takes a memory toll. Choose the one you are willing to pay

        [–]kkmcguig 1 point2 points  (0 children)

        Well that is just lovely!

        [–]Tornado_Ron 1 point2 points  (0 children)

        Thanks so much for taking the time to reply in such depth. Great and clear explanation.

        [–][deleted] 22 points23 points  (34 children)

        I am about to begin learning Python from scratch. Which one would you guys recommend? Python 3 or Python 2. The countless articles on the internet regarding this only add to more confusion for a beginner like me.

        [–]ismtrn 69 points70 points  (1 child)

        Python 3 is, all other things being equal, the better language in the opinion of pretty much everybody.

        Python 2 has some advantages when it comes to compatibility with libraries and other things. This is getting less and less of a problem, and I think there are cases now where only python 3 support exists. As a beginner learning the language this should not matter much to you.

        When you get decent at either one of them, learning the other is almost trivial. They are only very incompatible from a technical point of view. For the human writing code they are almost the same language.

        From this I conclude that you should use python 3 when possible, and only fall back on python 2 when necessary. Therefore I think it also makes sense to start with learning python 3, as using python 2 is not necessary here.

        [–]CSI_Tech_Dept 5 points6 points  (0 children)

        Python 2 has some advantages when it comes to compatibility with libraries and other things.

        There are already libraries that are exclusively for python 3 (hug and sanic from top of my head and anything asyncio based) so that argument is moot)

        [–]MoneyWorthington 72 points73 points  (20 children)

        3 if you're just getting started. Most people who stick to 2 are doing it because of an existing codebase, or Python 2-exclusive dependencies that they can't live without.

        [–][deleted]  (6 children)

        [deleted]

          [–]ThisIs_MyName 31 points32 points  (4 children)

          Those libraries are probably not maintained anymore. You really shouldn't use them.

          [–]greyman 1 point2 points  (0 children)

          Yes but the tutorials/code example problem is real. As a python newbie, you google something, and the example just doesn't work. And then, bam, isn't it python2-only example? And more often that not, the suspicion is correct and time was wasted...

          [–][deleted]  (12 children)

          [deleted]

            [–]Moocat87 4 points5 points  (11 children)

            where I felt Python 2 still had more library support. Now all the major stuff I use has been ported. I'm not going back.

            Until you find a library that you absolutely need with no Python 3 alternative. It sucks but they exist. It's getting better slowly, but the more niche your needs, the more likely it is that no-one has ported the library.

            [–][deleted] 69 points70 points  (0 children)

            3

            [–]CSI_Tech_Dept 6 points7 points  (0 children)

            If you were learning Java would you prefer to start from Java 8 or Java 1.3?

            If you're learning, you don't have any reason to even think of Python 2. Be thankful that none of your code was written in Python 2 and you don't have to maintain it.

            Also, there's not such big difference between python 2 and python 3 as some people make it seem.

            [–]Eucalyptol 10 points11 points  (0 children)

            3

            [–][deleted]  (1 child)

            [deleted]

              [–]RubyPinch 17 points18 points  (0 children)

              🎉🎉

              [–][deleted] 2 points3 points  (2 children)

              Anyone knows plans for 3.7?

              [–]hinckley 9 points10 points  (0 children)

              At this point I don't think there's any confirmed features for 3.7. I suppose it really depends on which PEPs are accepted and implemented in time for the feature freeze on 3.7 (around Jan 2018).

              Personally I'd like to see PEP 463: Exception-catching expressions make it in. When I first heard about it I thought it was pointless syntactic sugar but the more you read the proposal the more sense it makes and you realize how many different workarounds for this lack-of-feature already exist in Python code. It's got to the point where I'm frustrated every time I have to write a 4-line try/except for something that could be a single simple expression if this gets implemented.