-4

People have this exact same problem on a regular basis. Here's one from an hour ago:

randint in Python 3.5 doesn't work

Can we maybe just scan their code as they type it and if we see

if <name> == <value> or <value>

have a pop up telling them to look at another question like this first.

(The issue, for people not familiar with Python, is that the way this works is it sees if (<name> == <value>) or <value>, and in Python, most <value> evaluate as True, so this almost always ends up being a True statement. The person entering it thought that it would mean something like if <name> == (<value> or <value>)... which also isn't what they want. What they really want is if <name> in (<value>, <value>)). But it's valid Python and its how you could say it in English, so they jump to that incorrect phrase above that I suggest scanning for.)

This one is just so, so easy to detect with a regex, and so, so common.

3
  • 5
    Well, we already have a built in solution for this. Vote to close as a duplicate of a canonical question on the topic.
    – user4639281
    Sep 29, 2015 at 20:45
  • 1
    @TinyGiant - xkcd.com/1205 - This gets asked often enough and is easy enough that it's worth the time to write a bit of code to automate it. The close queue is long enough without this crap in it. Lets stop the question from being asked. Sep 29, 2015 at 20:46
  • 4
    It'll normally get dupe hammered fairly quickly - feel free to cast a close vote from the most suitable listed on sopython.com/canon/22/… Sep 29, 2015 at 20:48

2 Answers 2

8

This is so common that the Python chat room has an entry for it in their canonical question reference. Why doesn’t if x == 'A' or 'B' or 'C' do what I expect? (Yeah, the interface could be better, I don't have a lot of free time.) There are three targets, depending on the specific error the user made, but two of them are closed as dupes of the canonical question.

This will normally be caught and closed quickly. If you come across such a question, vote to close it as a duplicate.

1
  • Better than wasting the time of people here to answer questions, why not just head these off though and show the answer before you finish writing the question? Sep 29, 2015 at 22:38
3

Feels like an overkill to me. In Java, for example, I see a question about comparing object with == instead of equals almost on a daily basis, and I'm sure many more tags have their own pet reoccurring questions. When such a question comes up, just flag it as a duplicate and move on.

You must log in to answer this question.

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