[Tutor] Simple PassGen

Kayvan Sarikhani ksarikhani at gmail.com
Mon Feb 9 22:59:28 CET 2009


Ah, I see what you mean...this does seem to work:

#!/usr/bin/python
import random, string

pool = string.digits + string.letters + string.punctuation

outstr = ''

for i in range(8):
    outstr += random.choice(pool)

print outstr

Thanks very much!

K

On Mon, Feb 9, 2009 at 4:45 PM, Marc Tompkins <marc.tompkins at gmail.com>wrote:

> The print() function adds a newline.  Try this instead - above your loop,
> create an empty string; in place of yor print(), append to the string; at
> the end, print the whole string.
>
> I'd demonstrate but I'm typing this from my phone.
>
> ---  www.fsrtechnologies.com
>
> On Feb 9, 2009 1:35 PM, "Kayvan Sarikhani" <ksarikhani at gmail.com> wrote:
>
> Hello Tutors,
>
>   I've been messing around with a simple password generation script...no
> real crypto or anything, but a little stumped on the output.
>
> #!/usr/bin/python
> import random, string
>
> pool = string.digits + string.letters + string.punctuation
>
> for i in range(8):
>     print random.choice(pool)
>
>   This seems to do the job, but it lists the output with newlines, perhaps.
> For example:
>
> $ ./passgen.py
> t
> C
> (
> 2
> w
> P
> x
> 3
>
>   I thought that maybe adding "print random.choice(pool).strip()" might
> work but not having any luck with that. Is the output this way, simply
> because of the nature of the range, or can anyone point my in the right
> direction? Thanks in advance!
>
> K
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090209/094afcf0/attachment.htm>


More information about the Tutor mailing list