The following script read the content of the "file2.txt" text file and displays it on the REPL output.
+
+
<syntaxhighlight lang="python">
+
with open( 'file2.txt', 'r' ) as _file:
+
s = _file.readline()
+
while s:
+
print( s.strip('\r\n') )
+
s = _file.readline()
+
</syntaxhighlight>
+
+
Notes:
+
* the ''''r'''' mode is used to read text file.
+
* the {{fname|readline()}} read and return a line from the file (including the carriage return & line feed.
+
* the {{fname|strip('\r\n')}} remove the carriage return & line feed from the readed line. Otherwise it will also be printed to the REPL (which result into a double line feed).