iNTERFACEWARE Products Manual > Learning Center > Learning Python > File Reading and Writing > Reading From a File |
|
Looking for Iguana v.5 or v.6? Learn More or see the Help Center.
Python provides many different ways to read data from a file. You can:
To read a line of data from a file, use readline():
This function reads a line of data and returns it as a string. The line of data includes the trailing newline character. If there is no more data left to read, readline() returns the empty string.
The read() function reads the entire file into a single string:
The readlines() function reads the entire file into a list, with each line of the file contained in an element of the list:
|