3

I edited python script like below.

def func(file_obj)
    str="test"
    file_obj.write(str)

def main():
    f=open("test.txt", 'w')
    func(f)
    f.close()

if __name__=='__main__':
    main()

And then error happened like below.

File "test.py", line 2
def func(file_obj)
                 ^
SyntaxError: invalid syntax

How to pass file object as function parameter?

1 Answer 1

14

you forgot to add : after the definition. the code looks fine

def func(file_obj):

Sign up to request clarification or add additional context in comments.

Comments

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.