that person
Nice to meet you.
Question statistics
Question and answer scores are definitely factors that can be taken into consideration. There are many more things I consider:
the question view count (which gives some indication of how good the title is at pulling in search engine traffic);
the number of linked questions (i.e., have people already been using the question as a duplicate target?);
the diversity of answers available (e.g. for a how-to question, I look for an answer section that covers all the natural approaches to the problem, and ideally isn't full of obscure or roundabout solutions);
my own subjective evaluation of the question and answer quality (i.e., how they're already written; I also do a fair bit of editing when there's something that can be easily fixed, but I'd rather not do a lot of work if I don't have to. After all, that risks accusations of going against the authors' intent.)
In theory, per the FAQ on SE, answer quality is the primary criterion; but I personally think there are good reasons not to give that too much weight. It also doesn't really say how to assess the answer quality. As a curator entrusted with the ability to do these things unilaterally, I generally trust my own judgment here; but I do take prior voting into consideration, and also solicit opinions from my peers. (See the last section for details.)
WRT question age:
The only point I see in favor of that decision is that the closed question is newer.
This is in fact not relevant, per policy.
Yet, the fact it got a higher score over 6 years than the second one over 10 years should hint that it is more useful to readers.
Arguably. These scores don't count anonymous feedback from logged-out users or users with low reputation who can't cast votes normally; it's known that these results can diverge significantly from the community. I'm not aware, however, of a way to view this information for a specific question, even with the 10k reputation "moderator tools". But yes, there is a valid argument there.
The matter of duplication
Its top answer, while ok for that question, does not actually answer the question that got closed as duplicate.
The duplicate target had already been established as the canonical for the underlying problem. I closed the other question as a duplicate because a) I recognized that the underlying problem was the same and b) it did not look like a better Q&A for the problem - mainly on the (lack of) strength of the question.
We want canonicals to explain the question concisely, because they will be viewed by a lot of people and we want those people to recognize quickly that their own problem matches. The closed question asks about a needlessly specific setup for the problem, which would alienate other readers.
That said, my considered opinion is that the canonical does answer the question being asked in the closed post. For reference, that is:
So it seems that the relative path used in open(...)
is only relative to where the originating file is being run from (i.e __name__ == "__main__"
)? I don't want to use absolute paths. What are some ways to deal with this?
The answer, of course, is that it is relative to the program's current working directory; and that other than using absolute paths, it can be dealt with by changing the current working directory.
Meanwhile, the top answer on the canonical tells us:
Make sure you're in the directory you think you're in with os.getcwd() (if you launch your code from an IDE, you may well be in a different directory)
You can then either: Call os.chdir(dir), dir being the folder where the file is located, then open the file with just its name like you were doing....
and:
A relative path is a path that does not start with your computer's root directory, and is instead relative to something called the working directory. You can view Python's current working directory by calling os.getcwd().
IOW: the relative path is relative to the program's current working directory; and in order to make it work, the current working directory has to match the directory you wanted to use. The answer also explains the tools needed both to check what that directory is and to change it. I don't understand how that could be argued not to be answering the question.
"But the OP of the closed question also wants to know specifically about setting the CWD based off the current script location" - well, no; the top answer inferred that that would be useful, it wasn't asked. But if it were asked, that would lower the quality of the question, by making it less focused (we also have a canonical specifically for getting the path of the current file's containing folder, and the rest is straightforward).
Re acting unilaterally etc.
no voting as that person has high reputation
In fact, the criterion is a gold badge in one or more of the tags initially used for the question - in this case, python. This is supposed to indicate that I have the expertise needed to recognize duplicates like this.
I act unilaterally a lot of the time because there is a lot to do, and because I don't expect a lot of controversy on much of what I'm doing, and because it would often be difficult or time-consuming to reach any kind of consensus with others. (In general, posts on Meta that require subject-matter expertise to discuss, will not get much attention. Or so I'm told, anyway.)
I'm always happy to explain my reasoning (although it might take some time for me to get around to it, depending). Aside from Meta, I am the room owner for a chat room specifically about polishing up canonical questions for Python: https://chat.stackoverflow.com/rooms/247434/python-canon-discussion .
More generally is there a policy for which question to close as duplicate?
Not that I've been beaten over the head with yet. Certainly there are guidelines, and precedent, and a bunch of prior Meta questions about what to do in specific situations. I've even asked some of those. But outside of the FAQ it is pretty vague.
the person who closed it is not a neutral party, as they have posted their own answer to the second question.
I don't care about reputation. I have far more than is necessary to unlock every privilege afforded by the site (except, you know, the ones that require winning a community election). I put a ton of effort into that question - in order to ensure that all the information I thought was relevant for the question would be in a single answer, in a presentation style that I personally favour - to get a measly +2 out of it. It's honestly there more to collect related links, to help other curators close related questions.
I do, of course, like the idea of people seeing my answer and finding it useful; but that's because I genuinely do think it's useful. If I had decided that the other question was a better canonical, I would have migrated my answer to that question (and, if necessary, adapted it for the specific context of that question). Which is to say: I'm not motivated by trying to direct traffic to my answers; I'm motivated by trying to put my answers where they can be most useful.