Writing to a file

Nobody nobody at nowhere.com
Sat Mar 26 05:30:38 EDT 2011


On Fri, 25 Mar 2011 19:39:11 -0600, Littlefield, Tyler wrote:

>  >    with open(test_absname, 'w') as test:
> what's the difference in that and test = ...? I can see why you mentioned
> the os.path for cross-platform, but I don't understand why someone would
> use with over =.

Using "with" will automatically close the the file upon exit from the
block, whether by reaching the end of the block, return/break/continue, an
exception, etc.




More information about the Python-list mailing list