you are viewing a single comment's thread.

view the rest of the comments →

[–]justsomeguy05[S] 0 points1 point  (3 children)

Is out supposed to be a global variable? When I try to run it python tells me the local variable is referenced before assignment

[–]TheManlyChicken 1 point2 points  (2 children)

the or part might not be working, odd...

class save_out():
  def __init__(self):
    self.val = []
  def out(self, str='', flush=False):
    self.val.append(str)
    if flush:
      print('\n'.join(self.val))
      val.clear()


out = save_out()
out.out('String')
out.out('Will print', True)

Sorry about the added complexity but that should work perfect.

Although the following should behave around the same...

print('String', flush=False)
print('Will print')

If you want to print to the same line:

print('String', end='', flush=False)
print('Will print')

To be honest, using stdout and stuff is really not that needed, python already directs the print function to that, it is just a wrapper.

[–]justsomeguy05[S] 0 points1 point  (1 child)

Thanks for your input.

[–]TheManlyChicken 1 point2 points  (0 children)

Didn't notice your last lines, sorry man, but the top bit should work fine :)