Skip to content

Commit 846a727

Browse files
felixdivoholly1238
andauthored
Close file descriptor after use (pytorch#1575)
It also makes it no more complicated. Co-authored-by: Holly Sweeney <[email protected]>
1 parent 066b4d9 commit 846a727

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

intermediate_source/char_rnn_generation_tutorial.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ def unicodeToAscii(s):
9797

9898
# Read a file and split into lines
9999
def readLines(filename):
100-
lines = open(filename, encoding='utf-8').read().strip().split('\n')
101-
return [unicodeToAscii(line) for line in lines]
100+
with open(filename, encoding='utf-8') as some_file:
101+
return [unicodeToAscii(line.strip()) for line in some_file]
102102

103103
# Build the category_lines dictionary, a list of lines per category
104104
category_lines = {}

0 commit comments

Comments
 (0)