from sys import argv
script, origin, destination = argv
open(destination, 'w').write(open(origin).read())
How do I close the destination and origin file objects? Or is this something I don’t need to worry about?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In short straightforward scripts you shouldn’t worry about these issues, but in bigger programs you might run out of file descriptors.
Since version 2.5, Python has with statement, which can do the file closing for you: