2

I got a downvote for this answer to the question: How to add a header and/or footer to a sed or awk stream?, because the answer was written in the Python language.

I provided a Python answer because I found a text processing tag on that question. You know all Linux distributions have Python pre-installed. Is providing a Python answer for a question with the "text processing" tag wrong? If yes, then when or where can I provide Python type answers?

1
  • I'm a bit late to the game here, but it's not actually true that all Linux distributions have Python preinstalled (Arch doesn't), and certainly not all Unix-based systems (NetBSD doesn't).
    – Fox
    Jul 9, 2016 at 5:49

3 Answers 3

3

This question is pretty disingenuous; the post has a tag, but also and tags, the title is "How to add a header and/or footer to a sed or awk stream?", and the first sentence is "I have a bunch of output going through sed and awk.". The asker was pretty clear about wanting a sed or awk answer. With text processing in particular people have a bad habit of specifying a tool when it doesn't actually matter, but you have to check first; you can't just assume part of the question was optional and do it some other way.

3

I would repeat some of what the other answers said, and add some points that they missed. 

The question was explicitly about sed and/or awk, etc…

You point out that the question was tagged .  What you seem not to have noticed was that the OP didn’t use that tag; it got edited in four hours after the question was asked, by another person.  So you can’t really use the presence of the tag to justify your claim that the OP didn’t really want to restrict the answers to use sed or awk.  But, on the other hand, I don’t believe that it’s reasonable to expect every potential answerer to read the revision history and try to figure out what the OP wants and what he doesn’t.  Many questions, as posted, are incomprehensible nonsense, and therefore we allow other people (who may understand the underlying technology, and/or know English, better than the OP) to improve them.  You shouldn’t have to sift through chaotic previous versions of the question.  You should be able to answer the question, in its state at the time, and have your answer judged with reference to that version of the question, and not some past or future version.

Side note:  The person who added the tag to the question also posted an answer not using sed or awk.  One way to look at the narrative is that this person

  1. found a question that was completely and exhaustively answered,
  2. edited the question to make it slightly broader, and then
  3. posted an answer that would have been out of scope for the original answer, but was (arguably) in scope for the revised answer.

and it might be reasonable to ask whether that was appropriate behavior.

Other points:

  • You point to the tag and claim “all Linux distributions has have python pre-installed” to justify posting an answer using a tool other than what was asked for.  But, even if you interpret the question broadly, it’s hard to deny that it’s looking for a command-line answer.  All the other answers present a command that can be typed into a shell, and either hooked up to a pipe or given a filename parameter.  Yours doesn’t; it presents a Python program.  Sure, it’s just a matter of typing
    python -c 'your_answer'
    (or maybe python3 -c …)  But
    • you left out that part, which a beginner might not be able to figure out, and
    • it’s not that simple, because your answer uses both single quotes (') and double quotes ("), so it can’t just be enclosed in quotes.  To add insult to injury, I was able to change your code, end = "", to end = '', and it worked, so your use of both kinds of quotes was an unnecessary complication.  (I don’t know Python, so I don’t know whether you were following generally recognized good programming style, or just being arbitrary.)
  • The question says, “I have a bunch of output going through sed and awk.”  It does not say, “I have a file …”  All the other answers present a command that can take input from a pipe (or a file).  Your answer, as written, works only on a named file.  Again, I’m sure it’s trivial to change the Python code to read from the standard input, but you didn’t do it.

OK, that said, I believe that your answer doesn’t deserve downvotes.  But those are some of the reasons why I didn’t upvote it.

Disclaimer: I am the author of one of the other answers to the question.

1

It's most likely that you got downvoted because someone thought that you wasn't answering the quesiton.

Generally, when people ask how to solve X problem regarding text manipulation, they either want to embed it in their script, or use as a command to type in terminal. Python isn't well suited for this type of questions, because it's probably slower in text processing then specialised tools, plus question was asking specifically about sed and awk.

However; I think that no answer that addresses an issue is wrong answer. Even if by coincidence someone finds your answer helpful, it's still a plus.

So maybe your answer wasn't the best fit, but it isn't against rules either. I'd continue providing quality content. Some people tend to downvote too much; we can't do anything about it, but focus on the purpose of the site - helping others.

You must log in to answer this question.

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