%%capture cap --no-stderr print_something() with open('/path/to/capture.txt') as f: f.write(cap.stdout)