Stream: helpdesk (published)

Topic: show source in Jupyter Notebook


view this post on Zulip Gary Lai (Nov 28 2021 at 22:14):

Hi everyone, I'm just starting to learn Julia (coming from the Python deep learning world). I was wondering if there's an equivalent of ?? (for showing current function's source code) when working with Julia in Jupyter Notebooks. I tried @code_string from the "CodeTracking" package but it doesn't always work. I also tried the @lessmacro but it always shows me the entire module instead of just the current function.

view this post on Zulip Sundar R (Nov 28 2021 at 22:40):

There's been an open issue about this for several yaers, the CodeTracking package seems to be the current recommendation there. Does it not reliably work even with Revise.jl loaded too? I haven't used it since I don't use a notebook much.

view this post on Zulip Sundar R (Nov 28 2021 at 22:42):

There's also the @edit macro, in case you weren't aware - which also loads the entire file, but in an external editor, so it might be easier to navigate.

view this post on Zulip Sundar R (Nov 28 2021 at 23:39):

Here's a quick and dirty @showsource macro I just wrote, to show you some number of lines (that you can specify) starting from the function's beginning: https://gist.github.com/digital-carver/7fec89a2bb19e07066ad64abbb75c870 (assumes you have head and tail commands available on your system - if on Windows, you can install GNU utilities or find them within your git installation, and add their path to PATH).

view this post on Zulip Sundar R (Nov 28 2021 at 23:41):

I have an idea for a smarter version that tries to detect the end of the function, but it's pretty late here so that's gonna have to wait till late tomorrow. It'll still be hacky (i.e. based on line patterns rather than source code analysis), but should be good enough for interactive usage.


Last updated: Dec 28 2024 at 04:38 UTC