filmov
tv
Python - 066 : Read from a file in python #python #pythonprogramming #pythontutorial

Показать описание
The read() method:
This function returns the bytes read as a string. If no n is specified, it then reads the entire file.
Example:
#('r’) opens the text files for reading only
The readline() method:
This function reads a line from a file and returns it as a string. It reads at most n bytes for the specified n. But even if n is greater than the length of the line, it does not read more than one line.
The readlines() method:
This function reads all of the lines and returns them as string elements in a list, one for each line.
You can read the first two lines by calling readline() twice, reading the first two lines of the file:
This function returns the bytes read as a string. If no n is specified, it then reads the entire file.
Example:
#('r’) opens the text files for reading only
The readline() method:
This function reads a line from a file and returns it as a string. It reads at most n bytes for the specified n. But even if n is greater than the length of the line, it does not read more than one line.
The readlines() method:
This function reads all of the lines and returns them as string elements in a list, one for each line.
You can read the first two lines by calling readline() twice, reading the first two lines of the file: