Need help converting text to csv format

alex23 wuwei23 at gmail.com
Fri Nov 21 19:57:37 EST 2008


On Nov 22, 2:28 am, Joe Strout <j... at strout.net> wrote:
> A follow-up question here... is it really necessary to close things  
> like files in Python?

Not if you use a context manager (2.6+, available in 2.5 from
__future__):

with open('data.csv', 'wb') as csvfile:
  writer = csv.writer(csvfile)
  ...

The file is guaranteed to be closed at the end of the with-statement
block.



More information about the Python-list mailing list