Skip to content

Latest commit

 

History

History
33 lines (28 loc) · 1.58 KB

how-i-ask-gpt-4-to-make-tiny-python-scripts-in-practice.md

File metadata and controls

33 lines (28 loc) · 1.58 KB
title date tags
How I ask GPT-4 to make tiny Python scripts in practice
2024-08-22
automation
cost-optimization
heuristics
law-of-diminishing-returns
speed
software-dev
simple-suboptimal-solutions
python
gpt
  1. First get a working script. "Hey GPT-4, write me a ChatGPT script that does ."
  2. Manually check over the script and iterate until it's giving me what I want.
  3. "Now wrap the script into a click command-line interface." I almost always specify to use an --input flag and an --output flag.
  4. If the data it's working with is human-readable, "Make it so that if --input is not specified, it reads data from stdin."
  5. If the data it's writing is human-readable, "Make it so that if --output is not specified, it emits data to stdout."
  6. If the script is complicated enough that error logging is warranted: "Add logging and colorlog. Ensure all error messages are written to stderr so that it does not clash with output."

This advice is optimized for small Python scripts, usually under 200 lines in total, for automating semi-mundane tasks like

  • Converting CSV or JSON into a more structured Markdown document.
  • Cleaning up and working programmatically with Excel sheets.
  • Creating tiny REPLs to help with human categorization of mundane data.

I often find myself creating tiny scripts like this to shuffle things in and out of the various enterprise systems I work with. Python is famously the second-best tool for everything, and it hasn't let me down yet.