Skip to content

Commit 2243d30

Browse files
authored
Merge pull request tensorflow#2250 from cclauss/patch-15
file() was removed in Python 3, use open() instead
2 parents d1cdc44 + f70641f commit 2243d30

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

qa_kg/util/data_reader.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
# ==============================================================================
1515

1616
from collections import namedtuple
17-
from Queue import Queue
17+
try:
18+
from queue import Queue # Python 3
19+
except ImportError:
20+
from Queue import Queue # Python 2
1821
import re
1922
import threading
2023
import numpy as np
@@ -43,7 +46,7 @@ def __init__(self, config):
4346

4447
def read_kb(self):
4548
kb_raw = []
46-
for line in file(self.config.KB_file):
49+
for line in open(self.config.KB_file):
4750
sub, rel, obj = line.strip().split('|')
4851
kb_raw.append((sub, rel, obj))
4952
tf.logging.info('# of KB records: %d' % len(kb_raw))
@@ -55,7 +58,7 @@ def read_raw_data(self):
5558
raw = []
5659
tf.logging.info(
5760
'Reading data file {}'.format(self.config.data_files[name]))
58-
for line in file(self.config.data_files[name]):
61+
for line in open(self.config.data_files[name]):
5962
question, answers = line.strip().split('\t')
6063
question = question.replace('],', ']') # ignore ',' in the template
6164
raw.append((question, answers))

0 commit comments

Comments
 (0)