Converting a text file into a List with Python!

The following code reads all lines of a text file, removes the break-line characters and converts it all into a list.

For this script, i’ll assume that: the text file exists and has some content … (but you should verify this before performing the operations).

Using the “with” statement, it’s not necessary to explicitly close the text file. As soon as the textFile variable goes of scope, the file will be closed automatically.

The following two tabs change content below.
Breno RdV
Please allow me to introduce myself...I'm a former psychologist, with almost a decade worth of experience in Human Resources and People Management. Now a developer/software analyst working with PowerBuilder, C#, PowerShell and currently expanding to the world of Python, Xamarin, PHP Angular and (why not?) Unity.
Breno RdV

Latest posts by Breno RdV (see all)



Posted in Python and tagged , , , , .