Example of finished code, but ChatGPT finished my code without adding
any other AI bloat to it, is my code v0.0.
Have you actually run this code? Because I think it would fail
immediately in the first try/except.
Random remarks:
I usually put the main programme in its own function main(), usually
at the top of the script and have the if __name__ == '__main__'
boilerplate down the bottom, like this:
if __name__ == '__main__':
main()
this avoid accidental globals and make the scripts pupose more clear.
Without help text, it is not apparent what the various command line
options are for.
This line is effectively nonsense:
output_bytes = subprocess.check_output("/bin/echo Hello, World", shell=False)
Read the docs on subprocess.check_output to understand why. Plausible
syntacticly valid code which is nonsense is one of the things we
distrust about LLMs like ChatGPT.
Why aren’t you using print() for all these echo commands?
try:
answer = input("Proceed? ")
except KeyboardInterrupt:
# Handle the KeyboardInterrupt exception
print('User interrupted the script. Exiting...')
sys.exit(0) # Exit with status code 0 (success)
This is unusual. Often we don’t catch KeyboardInterrupt unless we need
to do some tidyup. We expect the user to indicate end of input with the
typical keystroke, which is usually ^D on UNIX/Linux and ^Z on
Windows.
When you’ve got codependent options like -r and -t it is normal to
handle them together in a single if-statement, eg:
if args.t:
if args.r:
... forbidden ...
else:
whatever args.r means ...
elif args.r:
... forbidden ...
else:
whatever args.t means
rather than repeating these checks in two separate if-statements.