尝试写入输出时写入文件时出错

问题描述 投票:0回答:1

在我创建的拼写检查程序中,我似乎在尝试写入输出文件时遇到错误。文件已创建但不是输出正在写入错误" <_io.TextIOWrapper name='f.txt' mode='w' encoding='cp1252'>name "

我一直在寻找解决方案。

print('Spell checking program for Exam 3 lab')

inputFile  = input('Enter the name of the file to input from: ')

outputFile = input('Enter the name of the file to output to: ')

f = open("linuxwords.txt", "r")

sent = open(inputFile+ '.txt', "r")

butt = open(outputFile+'.txt', 'w')

word = sent.readline()

print ("mispelled words are:")

while word:

    word = word.lower()
    success = False
    x = word.split()
    y=len(x)
    for i in x:
        success = False
        f = open("linuxwords.txt", "r")
        line = f.readline()
        while line:
            if i == line.strip():
                success = True
                break
            line = f.readline()
        f.close()
        if success == False:
            print (i)
    word = sent.readline()
    with open(outputFile+'.txt', 'w') as f:
        f.write(str(butt))
        f.write(i)
    try:
         '''''''
          I'm sure my mistake is here, idk
         '''''''
        f = open(outputFile, "w")
        f.write(i)
    except:
         print('The file',outputFile, 'did not open.')


sent.close()

''''''下面的结果''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Chris delatorre huis lst

python file input output spell-checking
1个回答
3
投票
f = open(outputFile)
f.write(i)

你打开文件进行阅读,然后尝试写入。

© www.soinside.com 2019 - 2024. All rights reserved.