| 55 | # from https://stackoverflow.com/a/16571630/6416660 |
| 56 | # alternative use redirect_stdout() from contextlib |
| 57 | class Capturing(list): |
| 58 | def __enter__(self): |
| 59 | self._stdout = sys.stdout |
| 60 | sys.stdout = self._stringio = StringIO() |
| 61 | # Make closing the StringIO a no-op |
| 62 | self._stringio.close = lambda x: 1 |
| 63 | return self |
| 64 | |
| 65 | def __exit__(self, *args): |
| 66 | self.append(self._stringio.getvalue()) |
| 67 | del self._stringio # free up some memory |
| 68 | sys.stdout = self._stdout |
| 69 | |
| 70 | |
| 71 | def only_int_check(val): |