summaryrefslogtreecommitdiff
path: root/ply/lex.py
diff options
context:
space:
mode:
authorMickaël Schoentgen <contact@tiger-222.fr>2018-11-01 17:28:20 +0100
committerMickaël Schoentgen <contact@tiger-222.fr>2018-11-09 10:29:21 +0100
commitd406e718d7ef23c2cb83bb38bc156f3cccffcf6f (patch)
tree4070d0fa86037b0269c8dac79d1e7a8f27a2e060 /ply/lex.py
parent0f398b72618c1564d71f7dc0558e6722b241875a (diff)
downloadply-d406e718d7ef23c2cb83bb38bc156f3cccffcf6f.tar.gz
Fix several ResourceWarning: unclosed file
Diffstat (limited to 'ply/lex.py')
-rw-r--r--ply/lex.py5
1 files changed, 2 insertions, 3 deletions
diff --git a/ply/lex.py b/ply/lex.py
index f95bcdb..f82a926 100644
--- a/ply/lex.py
+++ b/ply/lex.py
@@ -1055,9 +1055,8 @@ def runmain(lexer=None, data=None):
if not data:
try:
filename = sys.argv[1]
- f = open(filename)
- data = f.read()
- f.close()
+ with open(filename) as f:
+ data = f.read()
except IndexError:
sys.stdout.write('Reading from standard input (type EOF to end):\n')
data = sys.stdin.read()