Drop links or images here to add them to the editor.

Python heeft meerdere manieren om regels te lezen:

bestand = open("dikkertjeDap.txt", "r")

# Lees één regel
eerste_regel = bestand.readline()
print(eerste_regel)

# Lees alle regels als lijst
alle_regels = bestand.readlines()
bestand.close()

print(alle_regels)  # ['regel 2\n', 'regel 3\n', ...]

Overzicht:

Methode Geeft terug
read() Volledige inhoud als één string
readline() Één regel als string
readlines() Alle regels als lijst