Why use 'with' when working with files? Python Why use 'with' when working with files? Answer: It creates a temp file object that's only live during the indented scope, and is closed automatically, even if there's an exception that kicks you out of that scope. Learn More : Share this Share on FacebookTweet on TwitterPlus on Google+