Object for storing strings geted from prints
Posted
by evg
on Stack Overflow
See other posts from Stack Overflow
or by evg
Published on 2010-03-12T14:03:31Z
Indexed on
2010/03/12
14:07 UTC
Read the original article
Hit count: 180
class MyWriter:
def __init__(self, stdout):
self.stdout = stdout
self.dumps = []
def write(self, text):
self.stdout.write(smart_unicode(text).encode('cp1251'))
self.dumps.append(text)
def close(self):
self.stdout.close()
writer = MyWriter(sys.stdout)
save = sys.stdout
sys.stdout = writer
I use self.dumps list to store geted data from prints. Is it exists more convinient object for storing string lines in memory? ideally i want dump it to one big string. I can get it like this "\n".join(self.dumps) from code above. Mb it's better to just concat strings - self.dumps += text ?
© Stack Overflow or respective owner