[Tutor] Simple PassGen

Kayvan Sarikhani ksarikhani at gmail.com
Mon Feb 9 23:03:02 CET 2009


On Mon, Feb 9, 2009 at 4:53 PM, W W <srilyk at gmail.com> wrote:

> It's actually not the range but the print function. Print automatically
> prints a newline. If you were to create a string of what print does:
>
> print 'foo'
>
> 'foo\n'
>
> However, adding a trailing comma will eliminate that. It will still add a
> trailing space however. A better option would be like Marc suggests,
> although you have to do concatenation:
>
> mystr += random.choice(pool)
>
> You do have some other options though. Create a list and join it with '':
>
> In [148]: x = ['a','b','c']
>
> In [149]: ''.join(x)
> Out[149]: 'abc'
>
> Create a list, convert it to tuple, and use string formatting:
>
> In [151]: '%s%s%s' % t
> Out[151]: 'abc'
>
> Use sys.stdout.write instead:
>
> In [154]: for y in x:
>    .....:     sys.stdout.write(y)
>    .....:
>    .....:
> abc
>
> and a host of other options. The simplest is probably the concatenation
> though ;)
> HTH,
> Wayne
>

Thanks for the explanations, Wayne...the appending seems to do the trick,
but I'm also going to keep these in mind for future reference. So many
methods still left to learn. :)

K
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090209/936da7fd/attachment.htm>


More information about the Tutor mailing list