Re: Newbie question: does file("text.txt',"w").write("stuff") ever get closed?

Discussion in 'Python' started by Fredrik Lundh, Nov 18, 2005.

  1. "John Doe" <> wrote:

    > In an effort to avoid another potential mistake, I am wondering if the
    > anonymous file object/class/thingy that I create when I do file("text.txt',
    > "w").write("stuff") gets closed properly on exit or garbage collection or
    > something


    yes.

    > or if I always need to hang on to these things and close them myself.


    only if you want to 1) know exactly when the files are closed, or 2) are
    using so many files that the garbage collector cannot keep up with you
    (this never happens on CPython, but can, at least in theory, happen on
    other Python implementations)

    </F>
     
    Fredrik Lundh, Nov 18, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. komal
    Replies:
    6
    Views:
    1,469
    msalters
    Jan 25, 2005
  2. Jason
    Replies:
    0
    Views:
    230
    Jason
    Jul 6, 2004
  3. Larry Woods

    Anyone ever done a binary Stream.write??? How?

    Larry Woods, Jun 12, 2004, in forum: ASP General
    Replies:
    2
    Views:
    248
    Larry Woods
    Jun 15, 2004
  4. Matt Kruse
    Replies:
    5
    Views:
    338
    Richard Cornford
    Sep 9, 2003
  5. Rex Gustavus Adolphus
    Replies:
    17
    Views:
    224
    Rex Gustavus Adolphus
    Mar 7, 2004
Loading...

Share This Page