Skip to content

Commit 9790b8f

Browse files
committed
unicode strings for 2.7 compatibility
1 parent ed2188e commit 9790b8f

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

intermediate_source/char_rnn_classification_tutorial.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@
6464
``{language: [names ...]}``. The generic variables "category" and "line"
6565
(for language and name in our case) are used for later extensibility.
6666
"""
67-
67+
from __future__ import unicode_literals, print_function, division
68+
from io import open
6869
import glob
6970

7071
def findFiles(path): return glob.glob(path)
@@ -93,7 +94,7 @@ def unicodeToAscii(s):
9394

9495
# Read a file and split into lines
9596
def readLines(filename):
96-
lines = open(filename).read().strip().split('\n')
97+
lines = open(filename, encoding='utf-8').read().strip().split('\n')
9798
return [unicodeToAscii(line) for line in lines]
9899

99100
for filename in findFiles('data/names/*.txt'):

intermediate_source/char_rnn_generation_tutorial.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474
and end up with a dictionary ``{language: [names ...]}``.
7575
7676
"""
77+
from __future__ import unicode_literals, print_function, division
78+
from io import open
7779
import glob
7880
import unicodedata
7981
import string
@@ -93,7 +95,7 @@ def unicodeToAscii(s):
9395

9496
# Read a file and split into lines
9597
def readLines(filename):
96-
lines = open(filename).read().strip().split('\n')
98+
lines = open(filename, encoding='utf-8').read().strip().split('\n')
9799
return [unicodeToAscii(line) for line in lines]
98100

99101
# Build the category_lines dictionary, a list of lines per category

intermediate_source/seq2seq_translation_tutorial.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@
8383
8484
**Requirements**
8585
"""
86-
86+
from __future__ import unicode_literals, print_function, division
87+
from io import open
8788
import unicodedata
8889
import string
8990
import re
@@ -208,7 +209,8 @@ def readLangs(lang1, lang2, reverse=False):
208209
print("Reading lines...")
209210

210211
# Read the file and split into lines
211-
lines = open('data/%s-%s.txt' % (lang1, lang2)).read().strip().split('\n')
212+
lines = open('data/%s-%s.txt' % (lang1, lang2), encoding='utf-8').\
213+
read().strip().split('\n')
212214

213215
# Split every line into pairs and normalize
214216
pairs = [[normalizeString(s) for s in l.split('\t')] for l in lines]

0 commit comments

Comments
 (0)