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" <sri...@gmail.com> wrote: On Mon, Feb 9, 2009 at 3:35 PM, Kayvan Sarikhani <ksarikh...@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@python.org http://mail.python.org/mailman/listinfo/tutor
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor