Created
May 24, 2026 13:08
-
-
Save liamHowatt/ee86b5934d4b2b77c3151e94761ab4eb to your computer and use it in GitHub Desktop.
clone of moreutils errno(1)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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