sys.stdout question

Steve Holden steve at holdenweb.com
Sun May 1 18:40:36 EDT 2005


chris patton wrote:
>>>>import sys
>>>>class stuff:
> 
> ...       things = []
> ...       def write(self, string):
> ...               self.things.append(string)
> ...
> 
>>>>def_stdout = sys.stdout
>>>>sys.stdout = stuff()
>>>>print 'this is a string.'
>>>>print 'This is another string.'
>>>>sys.stdout = def_stdout
>>>>print stuff.things
> 
> ['This is a string.', '\n', 'This is another string.', '\n']
> 
> Where are the newline characters coming from?
> 
The print statement automatically inserts a newline at the end of its 
output unless the statement ends in a comma. It also puts a space 
between the comma-separated items.

regards
  Steve
-- 
Steve Holden        +1 703 861 4237  +1 800 494 3119
Holden Web LLC             http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/




More information about the Python-list mailing list