Skip to content

IOError: File not open for reading

Shuang0420 edited this page May 29, 2016 · 1 revision

错误代码

# get input file, text format
inp = sys.argv[1]
input = open(inp, 'r')
output = open('output.seq', 'w')

# read file and separate words
for line in input.readlines():
    line=line.strip('\n')
    seg_list = jieba.cut(line)
    output.write(' '.join(seg_list) + '\n')

# initialize the model
model = Word2Vec(LineSentence(output), size=100, window=3, min_count=5,workers=multiprocessing.cpu_count())

错误

IOError: File not open for reading

原因

打开模式仍然为写,没法读

正确姿势

# before initializing the model
output.close()
output= open('output.seq', 'r')

[[TOC]]

Clone this wiki locally