3 ms·
Quickest and dirtiest way I've found, but yes, not idiomatic Python: subprocess.check_output("grep ^$(whoami) /etc/passwd | awk -F : '{print $NF}'", shell=
by sixstringtheory 6y ago
Quickest and dirtiest way I've found, but yes, not idiomatic Python:
subprocess.check_output("grep ^$(whoami) /etc/passwd | awk -F : '{print $NF}'", shell=True, encoding="utf-8").strip()
I didn't test that particular line, but in general this is how I execute shell pipelines in Python.
- yjftsjthsd-h 6y ago:) I agree that that works, of course, but if we have to use shell=True and just shove the whole thing like that then it loses a rather lot of the "Python" appeal. Still valuable if you need to feed the output into Python, of course.