looping through a file

Miki Tebeka tebeka at cs.bgu.ac.il
Wed Apr 30 08:36:09 EDT 2003


Hello Psybar,

> hi all - ive just started with python (after having done java and c)
You've save the best for last :-)

> but it appears that python doesn't have a do... while...
> until loop.
See http://www.python.org/doc/current/tut/node6.html#SECTION006200000000000000000
and 
http://www.python.org/doc/current/tut/node5.html#SECTION005200000000000000000

> 
> #!/usr/local/bin/python
> 
> import cgi, string
> 
> form = cgi.FieldStorage()
> 
> if form.has_key('usernameField') and form.has_key('passwordField'):
>          users_username = string.strip(form['usernameField'].value)
>          users_password = string.strip(form['passwordField'].value)
authorised = 0
lines = open('users.dat').readlines()
for i in range(0, len(lines), 2):
    if (users_username == strip(lines[i]) and (users_password ==
strip(lines[i + 1]):
    authorised = 1
    break

HTH.
Miki




More information about the Python-list mailing list