0

Getting a syntax error on the apostrophe in this line

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()
1
  • 2
    Shouldn't those be variable names? Commented Oct 22, 2015 at 3:18

1 Answer 1

2

You can't have literals like that in a function declaration, it looks like your are confusing the declaration from the calling of a function:

def filecopy(infile, outfile):
    ...

# Later call the function
filecopy('example.txt','output.txt')

You can have default arguments:

def filecopy(infile='example.txt', outfile='output.txt'):
    ...

# But you still need to call it
filecopy()
# or
filecopy('fred.txt', 'wilma.txt')
Sign up to request clarification or add additional context in comments.

1 Comment

@Jerry Scirica Please accept the answer if it helps you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.