Working with Python Scripts
Leave the interpreter and start writing real .py files, including how to take input and print output.
Articles
Writing and Running a Python Script
A Python script is a file holding Python code, and it usually carries the .py extension.
Input and Output Systems in Python 3
A few functions, print() and input() among them, are the standard tools most I/O work in Python is built on.
Python Modules: the Import That Printed the Report
You pull one function out into its own file, import it, and the whole report runs again and eats your input. A module is a file, import runs it top to bottom, and one line decides which of the two jobs it is doing.
Python venv: the Install That Went Into the Wrong Python
pip install printed Successfully installed, and the next run raised ModuleNotFoundError on the same machine. Two interpreters, one install, and the variable your script checks is the one the interpreter never sets.
Python stdlib: the datetime json.dumps Refused to Write
A script that totals minutes per day dies on the line that writes the report. Four stdlib modules carry it, and one TypeError stands in the way.
Python debugging: the script that exits 0 with the wrong total
A totals script runs clean, prints a number, and the number is wrong. With no traceback to follow, you stop the program at the line that writes the value and read the dict from pdb.
Python try/except/finally: Handling a Blank CSV Cell Without Losing the Total
A minutes total dies on one empty CSV cell and prints nothing, so the rows that parsed fine are lost with it. Wrapping the conversion in try with except ValueError skips the bad row, and finally prints the summary even when the file is missing.
Python File I/O: Why the Second Read Came Back Empty
A notes script saves a line, prints it back, then counts zero. The file on disk is correct: read() left the pointer at the end, so the second call returned an empty string. Read once into a variable, or seek(0), and the count matches the file.