"print >> file" ok. What about "print > file" to truncate?

David Bolen db3l at fitlinxx.com
Mon Sep 4 23:55:14 CEST 2000


"Andrew Dalke" <dalke at acm.org> writes:

> To create a new file,
> 
>   open("filename", "w")
> 
> This creates the file if it doesn't exist, and truncates it if it does.
> Because of garbage collection, there's no need for an explicit close,
> so that's all you really need to have.

Just remember that leaving the explicit close to the GC might prevent
you from seeing a failure on the close (which could result in a loss
of data).  That may or may not be a problem depending on the use at
hand, but it's something to remain aware of.

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list