Skip to content

Commit 9f78b72

Browse files
Merge pull request geekcomputers#63 from frasercrossman/master
Enforce correct file closure
2 parents a0b4957 + 367ff33 commit 9f78b72

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

check_file.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Last Modified :
55
# Version : 1.0
66

7-
# Modifications :
7+
# Modifications : with statement added to ensure correct file closure
88

99
# Description : Check a file exists and that we can read the file
1010

@@ -14,7 +14,8 @@
1414
# Readfile Functions which open the file that is passed to the script
1515

1616
def readfile(filename):
17-
line = open(filename, 'r').read()
17+
with open(filename, 'r') as f: # Ensure file is correctly closed under all circumstances
18+
line = f.read()
1819
print line
1920

2021
def main():

0 commit comments

Comments
 (0)