简体   繁体   English

未创建/写入文件

[英]File not being created/written in

This is my code:这是我的代码:

org = "na"

OutputFile = open("F&FHOutput.txt", "a")

#Part 1
with open("input.txt") as file:
    for line in file:
        string,letter = line.strip().split(",")
        print(string + "," + letter + "," + string.replace(letter, ""))
        OutputFile.write(string + "," + letter + "," + string.replace(letter, ""))


#Part 2
def remove_strings_recursive(lines):
    if not lines:
        return ""

    word,letter = lines[0].rstrip().split(',')

    org = word

    word = word.replace(letter, '')

    print(org + "," + letter + "," + word)

    OutputFile.write(org + "," + letter + "," + word)
 
    return word + '\n' + remove_strings_recursive(lines[1:])

    

with open('input.txt', 'r') as file:
    lines = file.readlines()

    result = remove_strings_recursive(lines)


OutputFile.close()

I am trying to have it take the same things that are being printed and put them into a new file that the program creates if the file doesn't exist.我试图让它采用与正在打印的相同的东西并将它们放入一个新文件中,如果该文件不存在,该程序将创建该文件。 Every time I run the code, everything works fine but the output file is nowhere to be found.每次我运行代码时,一切正常,但找不到 output 文件。 Could someone please help?有人可以帮忙吗? (Sorry about the messy code) (抱歉代码乱七八糟)

Your file name has a special character ( & ), which can cause problems.您的文件名有一个特殊字符 ( & ),这可能会导致问题。 Try changing the file name to a more standard one.尝试将文件名更改为更标准的文件名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM