Verifying PEP8 in iPython notebook code

Make sure you’ve the module pycodestyle or flake8 to be able to check your code against the style guides. Then enable the magic function by using the pycodestyle_magic module (github repo): pip install flake8 pycodestyle_magic first load the magic in a Jupyter Notebook cell: %load_ext pycodestyle_magic and then turn on the magic to do compliance … Read more

How to set max output width in numpy?

I found this answer helpful in creating my own: import numpy as np np.set_printoptions(edgeitems=30, linewidth=100000, formatter=dict(float=lambda x: “%.3g” % x)) The absurd linewidth means only edgeitems and the window’s width will determine when newlines/wrapping occurs. If I shrink the window a bit, it looks like this, so you may still need to play with the … Read more

How do I set custom CSS for my IPython/IHaskell/Jupyter Notebook?

To add custom CSS to a particular notebook you can use HTML. Add and execute a regular Python code cell with the following content: from IPython.core.display import HTML HTML(“”” <style> // add your CSS styling here </style> “””) Alternatively (thanks @abalter) use the %%html cell magic: %%html <style> // add your CSS styling here </style>

Print not showing in ipython notebook

I had a similar printing problem when my first code cell was: import sys reload(sys) sys.setdefaultencoding(“utf-8”) Then I’ve commented the second and third lines like this: import sys #reload(sys) #sys.setdefaultencoding(“utf-8”) Reset the kernel and re-ran the program and now my print statements are working properly. Later on, I’ve found that when I was first having … Read more

How to call module written with argparse in iPython notebook

An alternative to use argparse in Ipython notebooks is passing a string to: args = parser.parse_args() (line 303 from the git repo you referenced.) Would be something like: parser = argparse.ArgumentParser( description=’Searching longest common substring. ‘ ‘Uses Ukkonen\’s suffix tree algorithm and generalized suffix tree. ‘ ‘Written by Ilya Stepanov (c) 2013’) parser.add_argument( ‘strings’, metavar=”STRING”, … Read more