will it cause any problems to open a read-only file & not close it?
Tim Roberts
timr at probo.com
Wed Mar 16 02:46:20 EST 2005
Sara Khalatbari <sarapythonlist at yahoo.com> wrote:
>Dear friends
>In a code, I'm opening a file to read. Like :
> lines = open(filename).readlines()
>& I'm never closing it.
>I'm not writing in that file, I just read it.
>
>Will it cause any problems if you open a file to read
>& never close it?
A file is closed when the last reference to it is deleted. Since you never
save a reference to this file, the last reference is deleted as soon as the
readlines() call finishes.
So, the file will be closed when you move to the next statement.
--
- Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the Python-list
mailing list