[Tutor] Simple PassGen

Marc Tompkins marc.tompkins at gmail.com
Mon Feb 9 23:32:49 CET 2009


Don't forget - the "print" statement is going away in 3.0, and you really
should get into the habit of using the print() function instead for new
code.  IIRC, print() does NOT support suppressing the newline, but IMNRC (I
might not remember correctly.)

---  www.fsrtechnologies.com

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

On Mon, Feb 9, 2009 at 3:35 PM, Kayvan Sarikhani <ksarikhani at gmail.com>
wrote:

> Hello Tutors,
> <snip>  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!
>

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

_______________________________________________
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/74d3727b/attachment.htm>


More information about the Tutor mailing list