[Techtalk] Python (resent)

Pierre Fortin pfortin at pfortin.com
Fri Apr 26 20:18:24 EST 2002


I just joined the list, so I missed the original post...

> > #!/usr/bin/python
> > password = "foobar"
> > 
> > while password!="unicorn":
> >     password=raw_input("Password : ")
> > print "Welcome in."
> > 
> > I have tried the script with for loops, with another while loop and
> > nothing works. Can someone suggest something or I am doomed from the
> > start to accept that I will never be able to program anything as
> > simple as I am sure this solution is!!!!!!!!!!!!!!

Actually, you script does work...  it doesn't hide the entered password
however.

Here's a simple one...

#!/usr/bin/env python

import getpass

user = getpass.getuser()
for i in range(3):
    pwd = getpass.getpass()
    if pwd in ["unicorn", "gemini", "capricorn"]:
        print user, pwd
        break

I threw in some extra goodies:
  env:  follows your path info to find python
  getpass:  disables password echo
  range():  no need to manually increment i
  if ... in [...]:  list searching.

HTH,
Pierre



More information about the Techtalk mailing list