Python 定义函数时出现语法错误

Python 定义函数时出现语法错误,python,function,python-3.x,Python,Function,Python 3.x,获取此行中撇号的语法错误 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() def filecop

获取此行中撇号的语法错误

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()

def filecopy('example.txt','output.txt'):#函数声明中不能有这样的文本,看起来您的声明与函数调用混淆了:

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')

这些不应该是变量名吗?@Jerry Scirica如果答案对你有帮助,请接受。