我倾向于通过读取另一个文件来创建一个新文件,但是当我尝试使用这个文件时,sys returns:No 这样的文件或目录:'new_text_file.txt'

I tend to create a new file by reading from another one, but when I try use this file, the sys returns:No such file or directory: 'new_text_file.txt'

text_list = []
with open("word5Dict.txt", "r") as f:
    for line in f:
        for word in line.split("#"):
            if word != "\n" :
                text_list.append(word)
f.close()

new_file = open("new_text_file", "w")
for word in text_list:
    new_file.write(word)
    new_file.write("\n")

class ScrabbleDict:
    def __init__(self, size, filename):
        self.dictionary = {}
        with open(filename,"r") as f:
            for line in f:
                key = line.replace("\n","")
                if len(key) == size:
                    self.dictionary[key] = key

我倾向于通过读取另一个文件来创建一个新文件,但是当我尝试在我创建的class中使用这个文件时,系统returns:没有这样的文件或目录: 'new_text_file.txt'

new_file = open("new_text_file", "w")

不会自动添加文件扩展名。使用

new_file = open("new_text_file.txt", "w")

相反。