Text files in Python — theory with a workout diary, modes that don’t forgive and hidden newlines (and the ‘w’ that ate my diary)

At the start of October I began logging my workouts in a text file: one line per session, with the date, the sport and the minutes. I had three sessions in it and wanted to add the fourth with a tiny five-line program. I ran it, opened the diary and… only today’s session was there. The other three were gone. This is the program, almost exactly as I wrote it:

# I wanted to log today's workout in my diary... and I wiped it
f = open('diary.txt', 'w', encoding='utf-8')     # this is how my diary was: three sessions
f.write('2026-10-05;running;35\n')
f.write('2026-10-06;bike;50\n')
f.write('2026-10-08;swimming;40\n')
f.close()


def count_sessions(name):
    f = open(name, 'r', encoding='utf-8')
    n = 0
    for line in f:          # one pass per line of the file
        n += 1
    f.close()
    return n


print('Sessions before:', count_sessions('diary.txt'))
f = open('diary.txt', 'w', encoding='utf-8')     # to "add" today's one... with 'w'
f.write('2026-10-09;running;30\n')
f.close()
print('Sessions after:', count_sessions('diary.txt'))

And this is what it printed:

Sessions before: 3
Sessions after: 1

From 3 sessions to 1. No error, no warning, nothing in red. The culprit is a single letter: the 'w' in the second open(). Opening a file in write mode empties it the moment it is opened, before anything is written. What I wanted was mode 'a' (append). Today we’ll see why this happens and everything else you need to read and write text files without nasty surprises.

In this article you’ll learn what a text file is, how to open and close it, the modes 'r', 'w' and 'a', the standard reading pattern with readline(), looping with for, read(), the two ways of writing (print(..., file=f) and write()), the with statement, encodings and the os module. You’re coming from regular expressions in Python, which will come in handy in the exercises, and when you finish you have the text files practice. Our running example is my workout diary.

What is a text file?

A text file is a sequence of characters stored outside the program, on disk. Among those characters are the line endings, the '\n' character. That’s why you can also see it as a sequence of lines: each line is a run of characters ending in '\n'. .txt, .csv and .html files, and your own .py files, are all text files.

This is my diary, the file workouts.txt we’ll use throughout the theory:

# workout diary: date;sport;minutes
2026-10-05;running;35
2026-10-06;bike;50

2026-10-08;swimming;40
2026-10-09; running ;30
2026-10-11;yoga;twenty
2026-10-12;soccer;90
2026-10-14;bike;45

Notice it isn’t perfect, and that’s on purpose: it has a comment at the top, a blank line (the fourth), a line with extra spaces around running (and, although you can’t see it here, two spaces and a tab at the end), and a yoga session with twenty written in words. Real files look like this.

A file lives outside your program. Programs create, change and delete files, but the operating system’s file management system looks after them. That’s why talking to a file has three stages: open (connect the program to the file), transfer (read or write) and close (release the connection and finish any pending writes).

Opening and closing a file

You open it with the open() function, which takes the file name and returns a handle: an object that represents the connection. From then on you work with the handle (f), not with the name.

# The three stages: open, transfer and close
f = open('workouts.txt', 'r', encoding='utf-8')   # 1. open: f is the file handle
first = f.readline()                              # 2. transfer: reads up to the first '\n', included
f.close()                                         # 3. close: releases the file
print(first, end='')    # the line already has its '\n'
print(repr(first))      # repr() shows the '\n' that print() hides
print(f.closed)         # True: the handle is already closed

When you run it:

# workout diary: date;sport;minutes
'# workout diary: date;sport;minutes\n'
True

Step by step:

  • open('workouts.txt', 'r', encoding='utf-8'): the first argument is the name; if you only give the “short” name, Python looks for it in the working folder (the one the program runs from). The second, 'r', is read mode (it’s the default, so open('workouts.txt') would do the same). The third, encoding, says how the characters are encoded; we’ll see it further down.
  • f.readline() reads one line: from where it stopped up to the next '\n', included.
  • f.close() closes it. Afterwards, f.closed is True.
  • The first line appears twice: with print(first, end='') it looks like it does in the file; with repr(first) you see what’s really there, with the final '\n' in plain sight.

FileNotFoundError: opening something that doesn’t exist for reading

Mode 'r' requires the file to exist. If you misspell the name (or you’re in another folder), it blows up:

# 'r' requires the file to exist (mine is called workouts.txt)
f = open('workout_log.txt', 'r', encoding='utf-8')

The message is very clear:

Traceback (most recent call last):
  File "missing.py", line 2, in <module>
    f = open('workout_log.txt', 'r', encoding='utf-8')
FileNotFoundError: [Errno 2] No such file or directory: 'workout_log.txt'

Running the program from a different folder. If the working folder in VS Code or the terminal isn’t the file’s folder, open('workouts.txt') won’t find it even though it’s “right there”. Check the path, or use os.path.exists() before opening (you’ll see it at the end).

Modes ‘r’, ‘w’ and ‘a’

The three modes you’ll use with text files:

ModeWhat forIf the file doesn’t existIf it already exists
'r'readingFileNotFoundErrorreads it from the start
'w'writingcreates it emptyempties it on opening
'a'appendingcreates it emptywrites at the end, deletes nothing

Here they are in action on the same file, week.txt:

# The three modes on the same file


def show(name):
    f = open(name, 'r', encoding='utf-8')
    print(repr(f.read()))       # the whole file in one string, with the '\n' in plain sight
    f.close()


f = open('week.txt', 'w', encoding='utf-8')   # it does not exist: 'w' creates it empty
f.write('Monday;running;35\n')
f.close()
show('week.txt')

f = open('week.txt', 'a', encoding='utf-8')   # 'a': the cursor starts at the end, nothing is deleted
f.write('Tuesday;bike;50\n')
f.close()
show('week.txt')

f = open('week.txt', 'w', encoding='utf-8')   # 'w' again: empties the file before writing
f.write('Wednesday;yoga;20\n')
f.close()
show('week.txt')

The show() function reads the whole file with read() (coming up shortly) and displays it with repr(). This is the output, one line per call:

'Monday;running;35\n'
'Monday;running;35\nmartes;bike;50\n'
'Wednesday;yoga;20\n'
  1. The first 'w' creates week.txt (it didn’t exist) and writes Monday.
  2. The 'a' puts the cursor at the end and writes Tuesday after it: now there are two lines.
  3. The second 'w' empties the file when it opens it and writes Wednesday. Monday and Tuesday are gone.

That’s exactly what happened to me in the opening story, and the diagram sums it up:

Modes r, w and a Three columns showing the same file before and after opening it in mode r, w and a. Same file, three opening modes open(‘week.txt’, ‘r’) Before Monday;running;35⏎ After Monday;running;35⏎ cursor at the start Reads. Changes nothing If missing: FileNotFoundError open(‘week.txt’, ‘w’) Before Monday;running;35⏎ After Wednesday;yoga;20⏎ write(…) writes Empties the file on opening If missing, creates it open(‘week.txt’, ‘a’) Before Monday;running;35⏎ After Monday;running;35⏎ Tuesday;bike;50⏎ cursor at the end Appends at the end If missing, creates it
The three modes on the same file: ‘r’ only reads, ‘w’ empties it before writing and ‘a’ writes after what was there.

Before writing open(..., 'w'), ask yourself: “do I mind losing what’s in this file?”. If the answer is yes, you want 'a'. 'w' is for files that are rebuilt from scratch every time, like a report.

The standard reading pattern with readline()

readline() reads one line every time you call it. When there are no lines left, it returns the empty string ''. That gives you the classic “loop until a condition holds” pattern:

# Standard reading pattern: readline() until it returns ''


def show(name):
    f = open(name, 'r', encoding='utf-8')
    line = f.readline()          # try to read the first line
    while line != '':            # '' only comes at the end; a blank line in the file is '\n'
        print(line, end='')      # the line already has its '\n': end='' avoids an extra blank line
        line = f.readline()      # the next one (or '' if it is over)
    f.close()


show('workouts.txt')

The output reproduces the file exactly:

# workout diary: date;sport;minutes
2026-10-05;running;35
2026-10-06;bike;50

2026-10-08;swimming;40
2026-10-09; running ;30  	
2026-10-11;yoga;twenty
2026-10-12;soccer;90
2026-10-14;bike;45

The order is: open, try to read the first line, and while what you read isn’t '', process it and read the next one. This is how the first four passes go:

Passline before processingline != ''?What gets printed
1'# workout diary: date;sport;minutes\n'yesthe comment
2'2026-10-05;running;35\n'yesthe first session
3'2026-10-06;bike;50\n'yesthe second
4'\n'yesa blank line
…………
10''nonothing: the loop ends

Look at pass 4. The blank line in the file is not the empty string: it’s '\n', which has one character. That’s why the loop doesn’t stop there. The empty string '' only arrives when there’s nothing left to read.

readline step by step A three-line file whose second line is blank, and what each of the four readline calls returns. Each readline() moves the cursor one line The file What readline() returns 2026-10-05;running;35⏎ 1. ‘2026-10-05;running;35\n’ a line with its newline ⏎ 2. ‘\n’ blank line: NOT the empty string 2026-10-06;bike;50⏎ 3. ‘2026-10-06;bike;50\n’ the last line end of file 4. ” end of file: the while stops
A blank line in the file is read as ‘\n’; the empty string ” only appears when there is nothing left to read.

Why end=”?

Because the line already carries its '\n', and print() adds another one of its own. Look at what happens with a plain print(line) on three.txt, a file with three sessions:

# The same pattern with a plain print(line)
f = open('three.txt', 'r', encoding='utf-8')
line = f.readline()
while line != '':
    print(line)          # the line's '\n' + the '\n' print adds = blank line
    line = f.readline()
f.close()

A blank line appears after every session:

2026-10-05;running;35

2026-10-06;bike;50

2026-10-08;swimming;40

You have two fixes: print(line, end='') (add nothing) or remove the newline before printing with line.rstrip(). rstrip() removes '\n', spaces and tabs from the end; strip() from both ends; lstrip() from the start.

repr(): see what’s really there

When a file behaves oddly, repr() is your magnifying glass: it shows each line as you’d write it in Python, with quotes, '\n' and tabs visible.

# See what is really in each line
f = open('workouts.txt', 'r', encoding='utf-8')
line = f.readline()
while line != '':
    print(repr(line))    # quotes, '\n', spaces and tabs in plain sight
    line = f.readline()
print(repr(f.readline()))  # already at the end: readline() returns the empty string
f.close()

Now everything shows:

'# workout diary: date;sport;minutes\n'
'2026-10-05;running;35\n'
'2026-10-06;bike;50\n'
'\n'
'2026-10-08;swimming;40\n'
'2026-10-09; running ;30  \t\n'
'2026-10-11;yoga;twenty\n'
'2026-10-12;soccer;90\n'
'2026-10-14;bike;45\n'
''

There are the two spaces and the \t on the sixth line, invisible with print(), and the last call to readline(), already at the end, returning ''.

Writing line = file.readline().rstrip() to read “already clean”. It works… until the file has a blank line: '\n'.rstrip() is '', and the while thinks the file is over. You’ll see it live in the exercises. Clean a copy inside the loop and let the condition look at the original line.

The file as a sequence of lines: for

A file opened for reading can be looped over with for, just like a list: each pass gives you a line. This is the “general traversal pattern” and it’s the most convenient way:

# The file as a sequence of lines: for, no readline()
f = open('workouts.txt', 'r', encoding='utf-8')
for number, line in enumerate(f, start=1):   # numbers the lines from 1, like an editor
    line = line.strip()                      # remove '\n' and spaces from both ends
    if line == '' or line.startswith('#'):   # no blank lines and no comments
        continue
    date, sport, minutes = line.split(';') # three fields separated by ';'
    print(number, date, sport.strip(), minutes)   # strip(): ' running ' has spaces inside the field
f.close()

With enumerate(f, start=1) each line comes with its number, like in an editor:

2 2026-10-05 running 35
3 2026-10-06 bike 50
5 2026-10-08 swimming 40
6 2026-10-09 running 30
7 2026-10-11 yoga twenty
8 2026-10-12 soccer 90
9 2026-10-14 bike 45
  • line.strip() removes the '\n' and the spaces and tabs from both ends of the line.
  • if line == '' or line.startswith('#'): continue skips the blank line (which after strip() really is '') and the comment. That’s why numbers 1 and 4 are missing.
  • line.split(';') cuts at the separator and gives three fields. But strip() only cleaned the ends of the line, not the ends of each field: ' running ' still has its spaces, hence the sport.strip().
  • The yoga session shows twenty. For now we only print it; if we tried int('twenty'), a ValueError would be raised. We handle it properly in the practice.

A handle can only be looped over once

The cursor moves forward as you read and doesn’t go back to the start by itself. If you loop over the same f twice, the second loop finds nothing:

# Looping over the same handle twice
f = open('workouts.txt', encoding='utf-8')   # no mode: 'r' by default
first = 0
for line in f:
    first += 1
second = 0
for line in f:          # the cursor is already at the end: nothing left to read
    second += 1
f.close()
print('First pass:', first, 'lines')
print('Second pass:', second, 'lines')

The result says it all:

First pass: 9 lines
Second pass: 0 lines

The file’s 9 lines are read in the first pass and the second one starts with the cursor already at the end. If you need to go through it again, close it and open it again (or store the lines in a list the first time).

Reading everything at once: read()

read() with no arguments returns the whole file in a single string. It’s handy for small files:

# read(): the whole file in one single string
f = open('three.txt', 'r', encoding='utf-8')
text = f.read()
f.close()
print(len(text))           # characters, counting every '\n'
print(text.count('\n'))    # how many lines end in '\n'
print(text.splitlines())   # list of lines, already without '\n'

With three.txt:

64
3
['2026-10-05;running;35', '2026-10-06;bike;50', '2026-10-08;swimming;40']

Let’s check it by hand. The lines are 2026-10-05;running;35 (10 + 1 + 7 + 1 + 2 = 21 characters), 2026-10-06;bike;50 (10 + 1 + 4 + 1 + 2 = 18) and 2026-10-08;swimming;40 (10 + 1 + 8 + 1 + 2 = 22). Plus the three '\n': 21 + 18 + 22 + 3 = 64. And splitlines() gives you the list of lines already without the newline.

read(n): n characters at a time

With a number, read(n) reads at most n characters and the cursor moves on. You can mix it with readline():

# read(n) reads n characters and the cursor moves on
f = open('three.txt', 'r', encoding='utf-8')
print(repr(f.read(4)))      # the first 4 characters
print(repr(f.read(7)))      # the next 7: it carries on where it stopped
print(repr(f.readline()))   # the rest of that line
print(repr(f.read()))       # everything that is left
print(repr(f.read()))       # nothing: we are already at the end
f.close()

Each call carries on where the previous one stopped:

'2026'
'-10-05;'
'running;35\n'
'2026-10-06;bike;50\n2026-10-08;swimming;40\n'
''

read(4) takes 2026; read(7) continues with -10-05; (7 characters: -, 1, 0, -, 0, 5, ;); readline() finishes that line; read() takes the rest, and one last read() finds nothing and returns '', just like readline().

When do I use each way of reading?

I want to…I useWhy
process line by linefor line in fthe clearest; nothing to call
stop as soon as I find somethingreadline() + whileyou decide when to carry on
get the whole text (count, search with regex)read()a single string; small files only
read an exact number of charactersread(n)fixed-width formats, headers

Writing: print(…, file=f) and write()

To write, open with 'w' or 'a'. You have two tools, and they differ precisely in what usually goes wrong: the newline and the type.

# Writing: print(..., file=f) versus f.write()
sessions = [('2026-10-15', 'running', 40), ('2026-10-16', 'yoga', 25)]

f = open('with_print.txt', 'w', encoding='utf-8')
for date, sport, minutes in sessions:
    print(date, sport, minutes, sep=';', file=f)   # converts to str and adds the '\n' by itself
f.close()

f = open('with_write.txt', 'w', encoding='utf-8')
for date, sport, minutes in sessions:
    n = f.write(f'{date};{sport};{minutes}\n')    # writes EXACTLY this string
    print('write wrote', n, 'characters')          # write returns how many characters it wrote
f.close()

for name in ['with_print.txt', 'with_write.txt']:
    f = open(name, 'r', encoding='utf-8')
    print(name, repr(f.read()))
    f.close()

Both files end up the same, but not by the same route:

write wrote 22 characters
write wrote 19 characters
with_print.txt '2026-10-15;running;40\n2026-10-16;yoga;25\n'
with_write.txt '2026-10-15;running;40\n2026-10-16;yoga;25\n'
  • print(date, sport, minutes, sep=';', file=f) does the usual thing but into the file: it converts everything to text (40 is an int and that’s fine), separates with sep and **adds the '\n' at the end**.
  • f.write(text) writes exactly the string you give it. Nothing more. No separators, no newline, no conversions. It returns how many characters it wrote: 22 for '2026-10-15;running;40\n' (10 + 1 + 7 + 1 + 2 + 1 = 22) and 19 for the yoga one (10 + 1 + 4 + 1 + 2 + 1 = 19).
print versus write The same session written with print and with write, and the TypeError when passing an integer to write. Two ways to write the same line print(date, sport, minutes, sep=’;’, file=f) 2026-10-15 ; sep running ; 40 str(40) ⏎ print adds it f.write(f'{date};{sport};{minutes}\n’) 2026-10-15 ; running ; 40 ⏎ you add it f.write(minutes) # 40, an int TypeError: write() argument must be str, not int
print() converts to text, separates with sep and adds the newline; write() writes exactly the string it gets, and only strings.

If you forget the '\n' with write(), the sessions get glued together:

# write() without '\n': everything ends up on the same line
f = open('glued.txt', 'w', encoding='utf-8')
f.write('2026-10-15;running;40')
f.write('2026-10-16;yoga;25')
f.close()
f = open('glued.txt', 'r', encoding='utf-8')
print(repr(f.read()))
f.close()

A single line with both sessions, no newline between 40 and 2026:

'2026-10-15;running;402026-10-16;yoga;25'

f.write(minutes) with a number. write() only accepts strings and raises TypeError: write() argument must be str, not int. Convert it with str(minutes) or, better, build the line with an f-string.

In the writing pattern, the loop goes over the source of the data (the list, another file…), not over the file you’re writing to, which is only the destination.

The with statement

Forgetting close() is very easy, and if the program fails before reaching it, the file stays open (and what you wrote may not be fully saved). with fixes this: it opens the file, gives you the handle and closes it by itself when leaving the block, whatever happens inside.

# with closes the file when leaving the block, whatever happens
total = 0
with open('workouts.txt', 'r', encoding='utf-8') as f:
    for line in f:
        parts = line.strip().split(';')
        if len(parts) == 3 and parts[2].isdigit():   # only lines with valid minutes
            total += int(parts[2])
    print('Closed inside the with?', f.closed)
print('Closed outside the with?', f.closed)
print('Valid minutes:', total)

Look at the handle’s state inside and outside:

Closed inside the with? False
Closed outside the with? True
Valid minutes: 290

Inside the with, f.closed is False; as soon as the indentation goes back, it’s True, without any close() written. The 290 minutes come from 35 + 50 + 40 + 30 + 90 + 45 = 290: the comment and the blank line don’t have three fields, and 'twenty'.isdigit() is False. The line with the spaces does count, because strip() leaves a clean '30'.

From today on, always open with with. You can open two files in the same one: with open('a.txt') as fin, open('b.txt', 'w') as fout:. We’ll use it to copy and filter.

Encoding: encoding=’utf-8′

Inside, a file is bytes. A text file stores characters encoded according to a standard, and to read them correctly you have to use the same standard they were written with. Today the usual one is UTF-8, where á takes two bytes. If you read with a different encoding, those two bytes are interpreted as two different characters. I use the name of a town in Gran Canaria, Gáldar, because it has an accent:

# The same line read with the right encoding and with another one
with open('ride.txt', 'w', encoding='utf-8') as f:
    f.write('Bike ride to Gáldar\n')

with open('ride.txt', 'r', encoding='utf-8') as f:
    print(repr(f.read()))    # the same encoding it was written with
with open('ride.txt', 'r', encoding='latin-1') as f:
    print(repr(f.read()))    # another encoding: the 'á' (2 bytes in UTF-8) shows up as 2 odd characters

The same line, read in two ways:

'Bike ride to Gáldar\n'
'Bike ride to Gáldar\n'

That Gáldar is the classic “broken” text you’ve probably seen on some website. On many Windows machines the default encoding hasn’t been UTF-8, so an open('x.txt') without encoding can misread the accents of a file that looks perfect on another computer.

Always write encoding='utf-8' when reading and when writing. It’s one more argument and it saves you the problem on every computer.

The os module: paths, folders and files

The os module lets you talk to the operating system: check whether something exists, create folders, join paths, list and delete. You have to import it with import os.

# The os module: paths, folders and files
import os

print(os.path.exists('workouts.txt'))       # True: it is in the working folder
print(os.path.exists('workouts2025.txt'))   # False: this is how you check BEFORE opening with 'r'
os.makedirs('backups/2026', exist_ok=True)  # also creates the intermediate folder; exist_ok: no error if it exists
path = os.path.join('backups', '2026', 'october.txt')   # joins the parts with the system separator
print(path)
with open(path, 'w', encoding='utf-8') as f:
    f.write('test copy\n')
print(os.listdir(os.path.join('backups', '2026')))     # what is inside the folder
print(os.path.isdir('backups'), os.path.isdir(path))   # folder yes, file no
os.remove(path)                                        # deletes the file (no recycle bin)
print(os.listdir(os.path.join('backups', '2026')))

Step by step:

True
False
backups/2026/october.txt
['october.txt']
True False
[]
  • os.path.exists(path): True or False. It’s the way to avoid FileNotFoundError before opening with 'r' (or to avoid overwriting something with 'w').
  • os.makedirs('backups/2026', exist_ok=True): creates the folder and any missing intermediate ones. With exist_ok=True there’s no error if they already exist (os.mkdir creates just one and fails if it’s already there).
  • os.path.join('backups', '2026', 'october.txt'): joins the parts with the system separator. Here, on Linux, it gave backups/2026/october.txt; on Windows it would give backups\2026\october.txt. That’s why you don’t type the slashes by hand.
  • os.listdir(folder): lists what’s inside. os.path.isdir(): is it a folder?
  • os.remove(path): deletes the file, with no recycle bin. Afterwards, the list comes out empty.

There’s more: os.getcwd() tells you the working folder (useful for the earlier error), os.chdir() changes it and os.rmdir() deletes an empty folder.

Common mistakes with files

Opening with 'w' to “add”. It empties the file on opening. To add, 'a'.

print(line) with lines read from the file: blank lines appear in between. Use end='' or rstrip().

Looping over the same handle twice. The second pass reads nothing: the cursor is at the end.

write() without '\n' (everything on one line) or with a number (TypeError).

Forgetting close(). With with it can’t happen.

Watch it step by step in Python Tutor

Python Tutor runs your code line by line and draws the variables. Choose Python 3. It has one limitation: it doesn’t open files from your disk. So we simulate the file with a string and iter(...): each next(f, '') plays the role of readline() and returns '' when there are no lines left.

# Python Tutor does not open files from your disk: the "file" is a string with its '\n'
text = '2026-10-05;running;35\n\n2026-10-06;bike;50\n'
f = iter(text.splitlines(keepends=True))   # each next() gives a line with its '\n', like readline()
total = 0
line = next(f, '')         # '' when there are no lines left, just like readline()
while line != '':
    clean = line.strip()   # clean a copy; the condition still looks at the original line
    if clean != '':
        date, sport, minutes = clean.split(';')
        total += int(minutes)
    line = next(f, '')
print('Total:', total, 'min')

The output you’ll see at the end:

Total: 85 min

What to watch:

  1. At the step where f is created, look at the list of lines: each one **carries its '\n'**, and the second one is just '\n'.
  2. On the second pass, line is '\n': the while condition is True (it isn’t ''), but clean is '' and the if skips it.
  3. Watch total go from 0 to 35 and from 35 to 85 (35 + 50 = 85): it only changes on the passes with a session.
  4. On the last call, next(f, '') returns '' and the loop ends. It’s exactly what readline() does at the end of the file.

Summary

ConceptThe essentials
Text filea sequence of characters, or of lines ending in '\n'
open(name, mode, encoding='utf-8')returns the handle; then close()
'r' / 'w' / 'a'read (must exist) / write (empties) / append at the end
readline()one line with its '\n'; '' at the end of the file
for line in fline-by-line loop; once per opening
read() / read(n)everything in one string / n characters
print(..., file=f)converts, separates and adds '\n'
f.write(s)writes strings only, exactly what you give it
withcloses the file by itself
osexists, makedirs, join, listdir, remove

Three ideas to take away:

  1. A blank line is '\n', not ''. The empty string only means “the file is over”.
  2. 'w' deletes, 'a' appends. Choose the mode thinking about what’s already in the file.
  3. print() adds the newline for you; write() adds nothing. And always open with with and encoding='utf-8'.

Now it’s time to use it for real: in the text files practice we read the whole diary with its odd lines, log sessions without deleting anything and write a monthly report to a new file. And with this topic you finish the whole FP1 syllabus: congratulations!

Next step: practiceText files in Python — practice with a diary summary, sessions logged without deleting anything and a monthly report (and the session that stuck to the day before)

Did this article help you? Here is how you can support SergioLearns →

Sigue aprendiendo

Leave a Reply

Your email address will not be published. Required fields are marked *