A coding journal is a program that asks you to type a daily entry about what you learned, then automatically saves it to a text file — stamped with the current date and time. It is one of the best first Python projects because it touches four skills at once: collecting user input, working with dates, writing to files, and structuring a real program.
Python gives you everything you need to build this journal without installing a single external library. Every tool used here — input(), open(), and the datetime module — ships with Python 3 out of the box. By the end of this tutorial you will have a working script that you can run each day to log your progress.
What You Will Build
The finished program does the following things in order. It greets the user, prompts for a journal entry, captures whatever they type, grabs the current date and time from the system, formats everything into a neat line, and appends that line to a file called coding_journal.txt. Every time the program runs, it adds a new entry without erasing the old ones. After writing, it prints a short confirmation so the user knows the entry saved correctly.
Here is what a completed coding_journal.txt file looks like after several runs:
[2026-04-01 09:14:22] Learned about variables and print() today. Wrote my first script.
[2026-04-02 08:55:07] Practiced loops. The while loop still trips me up but for loops feel natural.
[2026-04-03 10:02:44] Built a coding journal! Used input(), open(), and datetime all in one program.
You do not need to create coding_journal.txt yourself. Python creates the file automatically the first time the program runs. If the file already exists, Python opens it and moves to the end so that nothing is overwritten.
Build the correct Python statement to open a file in append mode using a context manager:
with open('coding_journal.txt', 'a') as f:. The with keyword starts the context manager. open() takes the filename first and the mode second — 'a' for append. The as f part gives you a variable name to reference the open file inside the block. The colon ends the statement. Using 'r' instead of 'a' would open the file for reading only, and print( is not part of a file-open statement.
The Four Building Blocks
Every line in this project comes from one of four Python tools. Understanding each one separately makes the full program easy to read when you put it all together.
input() — Collecting Text from the User
The input() function pauses the program, prints a prompt string to the screen, waits for the user to type something and press Enter, then returns whatever they typed as a string. The return value can be stored in any variable you choose.
entry = input("What did you learn today? ")
# The user types their answer and presses Enter.
# Whatever they typed is now stored in the variable `entry`.
datetime — Getting the Current Time
The datetime module is part of Python's standard library. You import the datetime class from it, call datetime.now() to get a snapshot of the current local date and time, and then call strftime() on that object to format it as a human-readable string.
from datetime import datetime
now = datetime.now()
timestamp = now.strftime("%Y-%m-%d %H:%M:%S")
print(timestamp)
# Output example: 2026-04-03 10:02:44
The format codes in strftime() always start with a percent sign. %Y is the four-digit year, %m is the two-digit month, %d is the day, %H is the hour in 24-hour format, %M is minutes, and %S is seconds. You can rearrange these in any order you prefer.
open() and Append Mode — Writing to a File Without Erasing It
Python's open() function takes a filename and a mode character as arguments. The mode character controls what you can do with the file. Append mode ('a') opens the file and moves the cursor to the very end of any existing content. A subsequent write places new text after everything already there. If the file does not exist at all, Python creates it.
- What it does
- Opens the file for reading only. The cursor starts at the beginning of the file. You cannot write to it in this mode.
- Behavior if file missing
- Raises a FileNotFoundError — the file must already exist.
- What it does
- Opens the file for writing. If the file already has content, that content is completely erased before your new data is written.
- Behavior if file missing
- Creates the file automatically.
- What it does
- Opens the file and moves the write cursor to the end. Any new data is added after existing content — nothing is overwritten. This is the mode to use for the coding journal.
- Behavior if file missing
- Creates the file automatically.
f-strings — Combining Text and Variables
An f-string lets you build a string that mixes fixed text with variable values. You prefix the string with the letter f, then place any Python expression inside curly braces {}. Python evaluates each expression and substitutes its result into the string at runtime.
timestamp = "2026-04-03 10:02:44"
entry = "Built a coding journal today."
line = f"[{timestamp}] {entry}\n"
print(line)
# Output: [2026-04-03 10:02:44] Built a coding journal today.
The \n at the end of the f-string is a newline character. It moves the cursor to the next line in the file so that each entry starts on its own line rather than running directly into the next one.
This function is supposed to write a journal entry to a file in append mode. One line contains a mistake that would erase all previous entries. Click the line you think is wrong, then hit check.
"w" to "a" on line 3. Write mode ("w") truncates the file to zero bytes every time it opens, so only the most recent entry would ever exist. Append mode ("a") positions the write cursor at the end of any existing content, leaving all previous entries intact.
Writing the Program Line by Line
Now that you understand each building block on its own, here is the complete program. Read through it once before running it so each line makes sense.
from datetime import datetime
def save_entry(entry, timestamp, filename="coding_journal.txt"):
"""Append a timestamped entry to the journal file."""
line = f"[{timestamp}] {entry}\n"
with open(filename, "a") as f:
f.write(line)
def main():
print("--- Python Coding Journal ---")
entry = input("What did you learn today? ")
if entry.strip() == "":
print("No entry recorded — you typed nothing.")
return
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
save_entry(entry, timestamp)
print(f"Entry saved to coding_journal.txt at {timestamp}")
if __name__ == "__main__":
main()
A few lines here are worth calling out for beginners:
if entry.strip() == "": — The strip() method removes leading and trailing whitespace from the string. This check prevents the program from saving a blank line if someone just presses Enter without typing anything.
if __name__ == "__main__": — This is a standard Python pattern. It means: only run main() when this file is executed directly. If another script imports this file as a module later, main() will not run automatically. It is good practice to include this from the start.
"Readability counts." — The Zen of Python, Tim Peters
Splitting the work into two functions — save_entry() for the file operation and main() for the user interaction — keeps each part easy to read and test separately. If you ever want to change the filename or the format of each entry, you only have to touch save_entry().
Do not confuse "a" (append) with "w" (write). Using write mode in a journal program will silently erase every previous entry each time the script runs. This is one of the most common mistakes beginners make when working with files in Python.
How to Build a Coding Journal in Python
Follow these six steps in order. Each step corresponds directly to a line or group of lines in the complete program shown above.
-
Import datetime
At the top of a new Python file, write
from datetime import datetime. This gives you direct access to thedatetimeclass without needing to prefix every call withdatetime.datetime. -
Prompt the user for an entry
Inside a
main()function, useentry = input("What did you learn today? ")to collect the user's text. Store the result in a variable namedentry. -
Generate a timestamp
Call
datetime.now().strftime("%Y-%m-%d %H:%M:%S")and store the result in a variable namedtimestamp. This produces a string like2026-04-03 10:02:44reflecting the exact moment the entry was written. -
Format the entry
In a separate
save_entry()function, build the final line using an f-string:line = f"[{timestamp}] {entry}\n". The square brackets make the timestamp easy to scan visually. The\nensures each entry ends on its own line in the file. -
Write to the file in append mode
Still inside
save_entry(), open the file usingwith open(filename, "a") as f:and then callf.write(line). Thewithstatement closes the file handle automatically when the block ends, even if an error occurs. -
Confirm the save
Back in
main(), after callingsave_entry(), print a confirmation line such asprint(f"Entry saved to coding_journal.txt at {timestamp}"). This gives the user immediate feedback that the program ran successfully.
Python Learning Summary Points
input()always returns a string. It pauses execution, shows your prompt, waits for the user to press Enter, and returns whatever they typed — always as text, even if they enter a number.- Append mode (
"a") is the safe way to write a growing log. Write mode ("w") destroys previous content every time the file is opened, which would turn your journal into a single-entry file. - The
withstatement (context manager) guarantees the file is closed cleanly after each write, preventing data loss from unclosed file handles. Always use it when working with files. - The
datetimemodule is part of Python's standard library — no installation required.datetime.now()captures the current local time, andstrftime()lets you format it however you like. - Separating concerns into two functions — one for user interaction and one for file writing — makes each part easier to read, test, and change without breaking the other.
Once the base program works, three natural extensions exist for further practice: wrap the main() logic in a while True loop so the program keeps accepting entries until the user types quit; add a separate function that reads the file and prints all previous entries to the terminal; or save entries as JSON objects instead of plain text so each record carries structured fields like date, topic, and mood. Each extension introduces a new Python concept while building directly on what you just learned.
Frequently Asked Questions
A Python coding journal is a program that prompts you to enter a daily text entry about what you learned, then automatically saves it to a text file with a timestamp. It uses the input() function to collect your entry, the datetime module to generate the current date and time, and file append mode to add each entry to the same file without overwriting previous ones.
You need four fundamental concepts: the input() function to read text from the user, the datetime module to get and format the current timestamp, the open() function with append mode ('a') to write to a file without erasing prior entries, and f-strings to format each journal entry before saving it.
Append mode, specified with the letter 'a' in Python's open() function, opens a file and positions the write cursor at the end of any existing content. Each new write adds to the end of the file rather than replacing it. If the file does not yet exist, Python creates it automatically.
Python's datetime module provides datetime.now(), which returns the current local date and time as a datetime object. You can format it into a readable string using the strftime() method with a format code such as '%Y-%m-%d %H:%M:%S', which produces output like 2026-04-03 14:30:00.
The with statement (context manager) ensures the file is automatically closed after the block of code finishes, even if an error occurs inside the block. This prevents resource leaks and avoids file corruption from unclosed handles. It is the recommended way to work with files in Python.
An f-string is a string literal that begins with the letter f before the opening quote. It lets you embed Python expressions directly inside curly braces within the string. In the coding journal, f-strings combine the timestamp and entry text into a single formatted line before writing it to the file.
By default, the program creates and writes to a file named coding_journal.txt in the same directory where the Python script is saved. Each run appends a new timestamped entry to that file without removing earlier entries.
No external libraries are needed. This project uses only Python's built-in tools: the datetime module from the standard library, the built-in open() function, and the built-in input() function. Any installation of Python 3 includes all of these by default.
You can open coding_journal.txt in any plain-text editor such as Notepad, VS Code, or TextEdit. You can also read the file from within Python using open() with read mode ('r') and print its contents to the terminal.
Several natural extensions exist once you have the base program working: add a loop so the program keeps accepting entries until you type quit, add a separate function to display past entries, allow the user to search entries by keyword, or save entries to a structured format like JSON instead of plain text.