Skip to content

Commit 54f91a2

Browse files
BoboTiGdbieber
authored andcommittedAug 28, 2018
Fix warnings in the diff example (#135)
Fix ResourceWarning (unclosed file) and DeprecationWarning ('U' mode is deprecated)
1 parent 6e0ca73 commit 54f91a2

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed
 

‎examples/diff/diff.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ def __init__(self, fromfile, tofile):
7474

7575
self.fromdate = time.ctime(os.stat(fromfile).st_mtime)
7676
self.todate = time.ctime(os.stat(tofile).st_mtime)
77-
self.fromlines = open(fromfile, 'U').readlines()
78-
self.tolines = open(tofile, 'U').readlines()
77+
with open(fromfile) as f:
78+
self.fromlines = f.readlines()
79+
with open(tofile) as f:
80+
self.tolines = f.readlines()
7981

8082
def unified_diff(self, lines=3):
8183
return difflib.unified_diff(

0 commit comments

Comments
 (0)