Read line by line from file with Python -Qiita
It seems better to use the with statement to read the file.
def main():
import inspect
filename = inspect.currentframe().f_code.co_filename
with open(filename) as fh:
for line in fh:
print(line.strip())
if __name__ == '__main__':
main()
exit(0)
Recommended Posts