How do I read the first line of a file?
Answer
Use file. readline() to read a single line from a file
Open a file in reading mode with the syntax with open(filename, mode) as file: with mode as “r” .
Call file.
readline()
to get the first line of the file and store this in a variable first_line .
Answer
Use file. readline() to read a single line from a file
Open a file in reading mode with the syntax with open(filename, mode) as file: with mode as “r” .
Call file.
readline()
to get the first line of the file and store this in a variable first_line .