Commit 2243d30c authored by Xin Pan's avatar Xin Pan Committed by GitHub
Browse files

Merge pull request #2250 from cclauss/patch-15

file() was removed in Python 3, use open() instead
parents d1cdc444 f70641f2
...@@ -14,7 +14,10 @@ ...@@ -14,7 +14,10 @@
# ============================================================================== # ==============================================================================
from collections import namedtuple from collections import namedtuple
from Queue import Queue try:
from queue import Queue # Python 3
except ImportError:
from Queue import Queue # Python 2
import re import re
import threading import threading
import numpy as np import numpy as np
...@@ -43,7 +46,7 @@ class SampleBuilder: ...@@ -43,7 +46,7 @@ class SampleBuilder:
def read_kb(self): def read_kb(self):
kb_raw = [] kb_raw = []
for line in file(self.config.KB_file): for line in open(self.config.KB_file):
sub, rel, obj = line.strip().split('|') sub, rel, obj = line.strip().split('|')
kb_raw.append((sub, rel, obj)) kb_raw.append((sub, rel, obj))
tf.logging.info('# of KB records: %d' % len(kb_raw)) tf.logging.info('# of KB records: %d' % len(kb_raw))
...@@ -55,7 +58,7 @@ class SampleBuilder: ...@@ -55,7 +58,7 @@ class SampleBuilder:
raw = [] raw = []
tf.logging.info( tf.logging.info(
'Reading data file {}'.format(self.config.data_files[name])) 'Reading data file {}'.format(self.config.data_files[name]))
for line in file(self.config.data_files[name]): for line in open(self.config.data_files[name]):
question, answers = line.strip().split('\t') question, answers = line.strip().split('\t')
question = question.replace('],', ']') # ignore ',' in the template question = question.replace('],', ']') # ignore ',' in the template
raw.append((question, answers)) raw.append((question, answers))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment