Issue
I'm aware of the %load
function (formerly %loadpy
) which loads the contents of a file (or URL, ...) into a new input cell (which can be executed afterwards).
I'm also aware of %less
, %more
and %pycat
, which show the contents of a file in a pager (which means in the notebook it's shown in the split-window at the bottom of the screen).
Is there a (magic) command to load a file and show its content (with syntax highlighting) in an output cell?
I.e. something like the following but with syntax highlighting of the result:
with open('my_file.py', 'r') as f:
print(f.read())
I want the file content to be stored with the .ipynb file but I don't want it to be executed when I do Cell -> Run All.
Is there a command similar to %psource
which shows the source code in an output cell instead of a pager?
Solution
No there is not way to do that with current magics, but it is pretty easy using pygments and returning IPython.display.HTML(...)
.
Answered By - Matt
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.