Closing a file before or after return?
gustafl at algonet.se
Fri Feb 9 14:58:39 CET 2001
I'm using Python 2.0.
Have a look at this function. It checks if a particular user (mail adress)
exist in a .htpasswd file. The user name is what comes before ':' on each
# Check if user exists
f = open('.htpasswd', 'r')
for line in f.readlines():
i = string.find(line, ':')
if line[:i] == user:
I'd like to close the file too, but I don't know where to put that
statement. Of course, the file should be closed in both cases -- not just
when the user is found.
More information about the Python-list