Reputation: 293
I would need to programmatically check that I am running code in a jupyter notebook from Julia
. One way would be using
isdefined(Main, :IJulia)
However this does not work for notebooks within vscode since they are run from outside IJulia is there a check that would work in this case as well?
Upvotes: 1
Views: 434
Reputation: 42214
What about @__FILE__
this yields REPL[_]
in Julia REPL, In[_]
in Jupyter and "/path/to/file.jl#==#hashocde" in Pluto so the test could be:
match(r"^In\[[0-9]*\]$", @__FILE__) != nothing
so you can check if the file ends with ".ipynb" if you want to find VSCode. Moreover: isdefined(Main, :VSCodeServer)
yields true
if you run from VSCode.
Upvotes: 1