These blog posts and discussion usually pit one language against others and often attempt to restrict a language to some specific context, ignoring that each user's experience, needs and preferences may be different. A more interesting debate would be language-agnostic, such as writing one-liners versus writing lengthy programs.

In short, the debate might be something like: What does the computer user prefer more: (a) writing one-liners or (b) writing lengthy programs. Not everyone will have the same answer. Knuth might prefer (b). McIllroy might prefer (a).

Assuming one reading this blog post knew nothing about programming languages, it seems to imply Python is not well-suited for one-liners, or at least not comparable to AWK in that context. Perhaps the interpreter startup time might have something to do with the failure to consider Python for one-liners.

I don't think Python is very well suited to one-liners, but it's not due to interpreter startup time (20ms on my machine). Rather, it's due to all the scaffolding needed, which AWK provides implicitly: AWK automatically reads input lines and splits them into fields, automatically initializes variables to the type's default value, and has terser syntax for things like regex matching.

Consider the following AWK one-liner which, for every input line that starts with a letter, prints the line number and the line's second field:

  awk '/^[A-Za-z]/ { print NR, $2 }'
The equivalent Python program has a ton more boilerplate: import statements, explicit input reading and field splitting, and more verbose regex matching:

  import re
  import fileinput

  inp = fileinput.input(encoding='utf-8')
  for line in inp:
      if re.match(r'[A-Za-z]', line):
          fields = line.split()
          print(inp.lineno(), fields[1])

I always thought we should make a short of Python for one liners inspired from awk, where the loop over the lines would be implied.

the line, lineno and fields would be predifined, and I guess re, os, shutil, pathlib and sys are pre imported. maybe the whole stdlib acts as if it's preimported, while only being imported lazyly

here it would be something like

```

if re.match(r'[A-Za-z]', line): fields = line.split() print(inp.lineno(), fields[1])

```

so

```

cat makefile | pyawk 'if re.match(r"[A-Za-z]", line): print(lineno, fields[1])'

```

I don't see a way out of multiple if statements requiring multiple lines though, otherwise you would have to introduce brackets to Python lol

Alec Thomas wrote a script like this called pawk.py (https://github.com/alecthomas/pawk). It reads input automatically, and for each line, defines "n" and "f" to the line number and fields list (among other things). It even supports /regex/ patterns. Even the print is implicit. So the example above would be:

  pawk '/^[A-Za-z]/ (n, f[1])'
By the way, triple backticks don't work on HN. You have to indent by 2 spaces to get a code block.