Closing a file before or after return?

Nicola Musatti objectway at divalsim.it
Fri Feb 9 15:20:10 CET 2001


Hi, I'm not even a newbie, but I'll venture an answer.

Gustaf Liljegren wrote:
> 
> 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
> line.
> 
> # Check if user exists
> def user_exist(user):
>   f = open('.htpasswd', 'r')
>   for line in f.readlines():
>     i = string.find(line, ':')
>     if line[:i] == user:
        ret = 1
        break
    else:
      ret = 0
    f.close()
    return ret

Best regards,
Nicola Musatti



More information about the Python-list mailing list