这是我的代码:
def translate():
'''
Prompts user to enter dictionary files and input and output files
Changes words in input file according to the dictionary file
Write translation in output file'''
dictFileName = input('Enter name of dictionary: ')
textFileName = input('Enter name of text file to translate: ')
outputFileName = input('Enter name of output file: ' )
f = open(dictFileName, 'r')
xf = f.readlines() # reads the whole file at once into a list
j = open(textFileName,'r')
xj = j.readlines()
processedDictFileLines = [] # create empty list
for line in dictFileLines: # begin for loop through lines in dictFileLines
words = line.strip().split('|') # strip off the newline character and split the string into its constituent substrings separated by the '|' character
processedDictFileLines.append(words[0] + ' ' + words[1])
k=0
while k<len(xj) :
if xs[k] in processedDictFile:
m=find(processedDictFile, xs[k])
xs[k]=processedDictFile[m+1]
k=k+1
myfile = open(outputFileName, "w")
myfile.write('xs')
myfile.close()
return myfile
translate()
但是如果我已经输入文件,为什么我会得到FileNotFoundError?