How To Read File Into List With 1 Line Of Code In Python
How do read the contents of a file in Python and insert these lines into a list? Using the built-in function open() and the asterisk operator * a file’s contents can easily be translated into a list with the following one-liner: [*open('my_file.txt')]. What Does open() Function Do? The built-in open() function has one required parameter and several optional parameters. The required parameter is the location of the file. If the file is located in the current folder where the Python script is run you can insert the name of the file, for example, test.txt. ...