在此行的撇号上获取语法错误
def filecopy('example.txt','output.txt'): #<- Error here on the "'"
infile = open('example.txt',)
text = infile.read()
infile.close()
infile = open('output.txt')
outfile.write(text)
infile.close()
答案 0 :(得分:2)
你不能在函数声明中使用这样的文字,看起来你在调用函数时会混淆声明:
def filecopy(infile, outfile):
...
# Later call the function
filecopy('example.txt','output.txt')
您可以拥有默认参数:
def filecopy(infile='example.txt', outfile='output.txt'):
...
# But you still need to call it
filecopy()
# or
filecopy('fred.txt', 'wilma.txt')