Skip to content

Instantly share code, notes, and snippets.

@liamHowatt
Created May 24, 2026 13:08
Show Gist options
  • Select an option

  • Save liamHowatt/ee86b5934d4b2b77c3151e94761ab4eb to your computer and use it in GitHub Desktop.

Select an option

Save liamHowatt/ee86b5934d4b2b77c3151e94761ab4eb to your computer and use it in GitHub Desktop.
clone of moreutils errno(1)
import errno
import os
import sys
def main():
exitcode = 0
errorcode_inverse = {v: k for k, v in errno.errorcode.items()}
for arg in sys.argv[1:]:
try:
num = int(arg)
except ValueError:
code = arg
num = errorcode_inverse.get(code)
if num is None:
print("ERROR: Not understood:", arg)
exitcode = 1
continue
else:
code = errno.errorcode.get(num)
if code is None:
exitcode = 1
continue
try:
message = os.strerror(num)
except ValueError:
exitcode = 1
continue
print(code, num, message)
exit(exitcode)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment