Random passwords generation (Python vs Perl) =)

Gabriel Genellina gagsl-py at yahoo.com.ar
Mon Jan 29 23:54:43 EST 2007


En Mon, 29 Jan 2007 01:58:39 -0300, NoName <zaz600 at gmail.com> escribió:

> Perl:
> @char=("A".."Z","a".."z",0..9);
> do{print join("", at char[map{rand @char}(1..8)])}while(<>);
>
> !!generate passwords untill U press ctrl-z
>
>
>
> Python (from CookBook):
>
> from random import choice
> import string
> print ''.join([choice(string.letters+string.digits) for i in
> range(1,8)])
>
> !!generate password once :(
>
> who can write this smaller or without 'import'?
>

Isn't it small enough? What's the point on being shorter?
I think you could avoid importing string (building the set of characters  
like the Perl code) but anyway you will end importing random, or os.urandom
Do you want more than one password? Wrap the print inside a while True:  
statement.
-- 
Gabriel Genellina




More information about the Python-list mailing list