Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seems not to be a reliable way of checking if the code is run in a notebook #155

Closed
mcallara opened this issue Feb 14, 2018 · 4 comments
Closed

Comments

@mcallara
Copy link

mcallara commented Feb 14, 2018

def in_ipynb():

@sebastianruder when I test this in my notebook cfg['IPKernelApp']['parent_appname'] returns a traitlets.config.loader.LazyConfigValue object. Please see this stackoverflow's thread. Thanks for the added feature!

ipykernel==4.8.1
ipython==6.2.1
jupyter==1.0.0
jupyter-client==5.2.2
jupyter-console==5.2.0
jupyter-contrib-core==0.3.3
jupyter-contrib-nbextensions==0.4.0
jupyter-core==4.4.0
jupyter-highlight-selected-word==0.1.0
jupyter-latex-envs==1.4.1
jupyter-nbextensions-configurator==0.4.0

@sebastianruder
Copy link

Thanks for pointing this out! Are you aware of something that works reliably? The SO thread also seems to be somewhat split on what's the best way to do this.

@mcallara
Copy link
Author

Not really, but maybe using get_ipython().class.name == 'ZMQInteractiveShell' would be better, for the time being.

@radekosmulski
Copy link
Contributor

Created a PR - not sure if this is the solution we would like to go with but if that would be the case the PR is ready 🙂

@jph00 jph00 closed this as completed Mar 6, 2018
@Edouard360
Copy link

Be careful in @mcallara 's answer
get_ipython().__class__.__name__
(You didn't escape the underscores...)

borisdayma pushed a commit to borisdayma/fastai that referenced this issue Aug 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants