PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, August 18, 2022

[FIXED] how to colored and ouput code in jupyter?

 August 18, 2022     colors, jupyter-notebook, output     No comments   

Issue

For a presentation I want to show internal code inside packages in Jupyter notebook, I could manage to get the code, but it's plain text (image[1]), Is it exist a way to color the output like image[2]?

here's my code:

import inspect

def printSource(obj):
    print(''.join(str(x) for x in inspect.getsourcelines(obj)[0]))

printSource(printSource)

I guess should be there a way, because when there's an error, shows colors like image[3]

1: actual, 2: expected, 3: actual error


Solution

You coud use %psource, but also you need to tell jupyter where to print, try this

from IPython.core import page
page.page = print

then, one per cell the function you want to show

%psource printSource


Answered By - Ivan C
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing