Nguyễn Nguyệt Ánh
New member
How do you read Top 10 lines in Python?
Answer
Use file.
readline() to print the first n lines of a file
Answer
Use file.
readline() to print the first n lines of a file
- a_file = open(“file_name.txt”) Open “file_name.txt”
- number_of_lines = 3.
- for i in range(number_of_lines): Print the first number_of_lines lines of a_file.
- line = a_file. readline()
- print(line)