2015-10-22 28 views
0

獲取有關撇號語法錯誤在這行獲得一個語法錯誤,同時定義一個函數

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

應該不是那些是可變名字呢? –

回答

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

好的,我明白了,感謝您的幫助! –

+0

@Jerry Scirica請接受答案,如果它可以幫助你。 – palsch

相關問題