Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1)

Unified Diff: Lib/shlex.py

Issue 18853: Got ResourceWarning unclosed file when running Lib/shlex.py demo
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/shlex.py Mon Aug 26 22:28:21 2013 +0200
+++ b/Lib/shlex.py Tue Aug 27 21:57:27 2013 +0800
@@ -292,13 +292,19 @@
if __name__ == '__main__':
if len(sys.argv) == 1:
+ f = None
lexer = shlex()
else:
file = sys.argv[1]
- lexer = shlex(open(file), file)
- while 1:
- tt = lexer.get_token()
- if tt:
- print("Token: " + repr(tt))
- else:
- break
+ f = open(file)
+ lexer = shlex(f, file)
+ try:
+ while 1:
+ tt = lexer.get_token()
+ if tt:
+ print("Token: " + repr(tt))
+ else:
+ break
+ finally:
+ if f:
+ f.close()
« no previous file with comments | « no previous file | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+