I am trying to read a file using the following statement:
input = open("input.txt").read().split('\n')
So basically my goal is to read the file line by line and store the results in an array. It works fine when the file is not empty. When the input file has only one line len(input), it is 1, as expected.
But when the file is empty, len(input)it still gives 1. What am I doing wrong?
source
share