News for hackers. Stuff that matters.
Re:Minimal safe Bash script template by sillysaurusx on Tuesday December 15, 2020 @01:03PM (#25432954)
Python isn't that readable when piping. From https://docs.python.org/3/library/subprocess.html#replacing-...

  output=$(dmesg | grep hda)
becomes

  p1 = Popen(["dmesg"], stdout=PIPE)
  p2 = Popen(["grep", "hda"], stdin=p1.stdout, stdout=PIPE)
  p1.stdout.close()  # Allow p1 to receive a SIGPIPE if p2 exits.
  output = p2.communicate()[0]
This isn't a contrived example. One reason I like using macros in Python is because it simplifies exactly this boilerplate.

You can write a simplifying function, but programs rarely do.

Re:Minimal safe Bash script template by powersnail on Tuesday December 15, 2020 @04:05PM (#25435256)
I agree. Subprocess isn't really a shell-ish pipe. And it's sometimes slow (at least it used to be).

This is why I use the shell overall, but when I need to process something that's better expressed in python, I use pypyp.

Re:Minimal safe Bash script template by sillysaurusx on Wednesday December 16, 2020 @02:12AM (#25439904)
Thanks for mentioning pypyp! It looks sweet.
Re:Minimal safe Bash script template by d0mine on Wednesday December 16, 2020 @10:58AM (#25444094)
Why would you reimplement piping? Just use the shell:

  output = check_output(“dmesg | grep hda”, shell=True)
Or regular Python string methods could be used instead of piping to grep.