17

There doesn't seem to be a consistent & clear way to determine if historic questions and their answers are related to Python 2 or Python 3. I have only ever used Python 3, so other than the obvious print statement difference, I struggle to identify if a thread from a few years back is Python 2 specific.

This is especially prevalent for questions from around 2008 to 2012

Sometimes there are clear edits made to the post to clarify how the posts relate to the different Python versions, or someone in the comment will say 'In Python 3 do this...'. But this is very ad-hoc

Am I missing a meta feature that helps users with this?

8
  • 1
    How about only looking for Python-3.x?
    – rene
    Commented Apr 25, 2019 at 10:13
  • 12
    I think the consensus is that a question is tagged python if the version doesn't matter and a version specific tag is added when questions only seek answer for a specific answer. Beyond that you can only hope an answer works for your version or ask in a comment if you're unsure. Or go cabbage in the Python chatroom.
    – rene
    Commented Apr 25, 2019 at 10:17
  • Thanks Rene that's a good idea, problem is older threads often are tagged just [python] because it was back when Python 2 was still the default
    – Andy
    Commented Apr 25, 2019 at 10:23
  • 1
    Yep, and thankfully some members with > 2K will take on a re-tagging if questions are popular and the confusions keeps returning
    – rene
    Commented Apr 25, 2019 at 10:25
  • 4
    To add to what rene said, all Python questions should have the generic python tag, and version-specific tags should only be added if the OP needs a version-specific answer. Unfortunately, the OP doesn't always know that they need a version-specific solution (eg, for Unicode questions), and answerers may neglect to add it for them. Also, there are tons of questions with version-specific tags, but no generic tag, so they slip under the radar of those who just watch the tag page (and annoy gold badgers who need to hammer them).
    – PM 2Ring
    Commented Apr 25, 2019 at 10:35
  • 1
    raw_input() , map / filter producing lists instead of generators and some other things hint towars 2.x as well - but if you are "new" they might not stand out that much Commented Apr 26, 2019 at 16:50
  • 2
    As a Python programmer (but not a big contributor to its tag), the current consensus looks quite stupid. There's no such a thing as "the version doesn't matter" - Py3 has sufficiently pervasive changes that, if you want to provide actual code in an answer, either you carefully craft "bi-sex" code (which is a PITA and often non-idiomatic), or you write code twice, or add distracting "change this if Py2" around. Somewhat like C and C++, Py2 and 3 are distinct languages that happen to be similar; you should either ask about one or the other, or in rare cases about code that is valid for both. Commented Apr 27, 2019 at 16:52
  • For questions with version-specific answers, I'll sometimes provide separate examples for Python 2 and 3.
    – Stevoisiak
    Commented Jul 9, 2019 at 19:28

2 Answers 2

23

As rene mentioned in a comment, the consensus is that ideally we use for anything python-related, and when the question itself has to do with specific differences between 2 and 3 we add or . The tag wikis support this distinction, but of course we know how well people read that sort of thing.

There are no special machineries in place to help you distinguish the python version. This problem is present in other tags, where obsolete or deprecated content sticks around and it's not always obvious that you're looking at something that should not be used. This general problem has been debated a lot on meta, and I don't think there's a clear solution. People tend to agree that highly voted answers with obsolete code (and python 2 is in this category now) should be preserved for the benefit of both the answerer and unlucky users having to work with legacy systems (such as python 2). It might be a solution to post new answers with modern solutions, or to dupe-close old Q&As to new ones prominently featuring the modern solution. I know I've edited deprecation notices on top of upvoted/accepted obsolete answers quite a few times.

But as a user trying to figure out if a given existing Q&A is python 2 or 3: you have to look at the syntax (Print statements or print functions? Bytes or unicode literals? Any str.decode or dict.iteritems etc?), look at the comments, look at the related documentation, and if all else fails run the code. A lot of the differences between 2 and 3 (or even older versions of 3 and newer versions) are syntactical, and trying to run the old version will either fully work or it will fail with an error. One notable difference is the handling of strings, which can give you different results between the two versions. But the good news is that python 3 has the correct behaviour, so almost always such problems reveal latent bugs in the python 2 version of the code.

6
  • 1
    "This general problem has been debated a lot on meta, and I don't think there's a clear solution." there is a solution. It stares us every moment we read a post.
    – Braiam
    Commented Apr 27, 2019 at 1:45
  • pyhton 2 still works for about 1/2 year. Even after that - you`ll find legacy code on systems not updating to 3.x for another 10-15years (we still deal with win95 and C# 2.0 code sometimes. Changing questions from 2.x to 3.x when they are labeled 2.7 seems unwise. Changing python to python 3 if labeled python as well. If they are identifyable - adding a python 2 label might work. Commented Apr 27, 2019 at 8:05
  • @Braiam I don't get it. Isn't that link about feature requests? If so, there's no solution right now, which is what I said. Commented Apr 27, 2019 at 8:12
  • 2
    @PatrickArtner python 2 has been gradually becoming obsolete for a decade. The EOL was even pushed out once. Since porting is costly the people who wanted to migrate should've started and finished long ago. And I never said anything about retagging or changing tagging habits going forward. Commented Apr 27, 2019 at 8:14
  • 1
    I misread it then :) Commented Apr 27, 2019 at 8:20
  • 3
    @AndrasDeak: Never underestimate the ability of large corporations to procrastinate. A few years ago, IBM opposed the removal of trigraphs from C on the grounds that some of its customers, including a "large financial institution," were still using EBCDIC and were therefore unable to portably encode curly braces.
    – Kevin
    Commented Apr 27, 2019 at 14:55
-3

I have a simpler way to do it: you don't. Or more accurately, you are only interested in the answers anyways. If you are looking at your search terms and you find the question which ask exactly what you are having issues about, wouldn't you click it?

How to print "Hello World"? is a timeless question. It never expires, nor it becomes irrelevant. Stack Overflow is supposed to produce artifacts for future readers. These future readers don't care about the version 12 years ago of your language. They want the answer that solves their problems now. Those interest are best served by the answers themselves, instead of the question. Lets see an example of this working.

How do I undo the most recent local commits in Git?

Since 2009, Wikipedia counts at least 15 releases, including a change between 1.x to 2.x. The question since the start hasn't changed. Nor has the top answer. Now, some people may claim that git is a special case, because Linus Torvalds doesn't break stuff. But that's irrelevant. The relevant part is that the question is exactly the same back then, than today. Even if we had to do some kind of git revert --last-commit or something, the question would've stayed the same, but now with two different answers that solve the problem.

For that reason, don't worry about whenever a answer was useful to your Python 3.8.3, just downvote it. And keep scrolling down until you find the one that works for you and upvote that one. That's how the system makes sure the top answer is useful for the higher share of users.

2
  • 4
    "For that reason, don't worry about whenever a answer was useful to your Python 3.8.3, just downvote it": am I misreading this or are you really suggesting that someone that has to support Internet Explorer 4 should downvote every javascript answer until they find one that is applicable to their situation? Commented Apr 27, 2019 at 8:39
  • @AndrasDeak if there a sizable amount of ie user out there that has the same question, that would cause an effect. I don't expect that to happen.
    – Braiam
    Commented Apr 27, 2019 at 11:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .