with open('/etc/passwd') as f: for line in f: print(line) # by using with statement u have no need to close the file.it auto exists after its use.