Hide SQL statements when running IPython notebook

2019-07-18 11:07发布

问题:

I'm using Django's django-extensions to run an iPython notebook with access to the Django models (as detailed here http://andrewbrookins.com/python/using-ipython-notebook-with-django/). When I make model queries, the notebook shows the underlying SQL queries executed by Django, like so:

Can I hide this SQL? It's so voluminous it makes the display unusable at times.

回答1:

with recent version, you could use

%%capture variable
the code

to capture stdout and stderr into a variable adding the --no-stdout flag

%%capture --no-stdout variable

wont capture stdout, thus displaying it.

Also, please, IPython (upper casse I) preferably, ipython accepted, but try to avoid iPython