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 @less
macro but it always shows me the entire module instead of just the current function.
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.
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.
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).
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: Nov 22 2024 at 04:41 UTC