首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >尝试写入输出时写入文件时出错

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

Stack Overflow用户
提问于 2019-05-02 03:32:34
回答 1查看 48关注 0票数 0

在我创建的这个拼写检查程序中,我似乎在尝试写入输出时得到了一个错误:创建了file.The文件,但错误的是" <_io.TextIOWrapper name='f.txt' mode='w' encoding='cp1252'>name ",而不是写入输出。

我试过寻找解决方案。

代码语言:javascript
复制
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()

‘下面的结果’考试3实验的拼写检查程序输入要输入的文件名: spw输入要输出到的文件名:f拼写错误的单词为: deks chris delatorre huis lst

EN

回答 1

Stack Overflow用户

发布于 2019-05-02 03:34:29

代码语言:javascript
复制
f = open(outputFile)
f.write(i)

您正在打开要读取的文件,然后尝试对其进行写入。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55941661

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档