Débugguer du code Python depuis Notebook Jupyter

In [8]:
%debug

def print_endline(i: int) -> None:
    print(1.0 / i)

def main() -> None:
    for i in range(10, -10, -1):
        print_endline(i)o

main()
> <ipython-input-7-a9361fd1acbd>(4)print_endline()
      2 
      3 def print_endline(i: int) -> None:
----> 4     print(1.0 / i)
      5 
      6 def main() -> None:

ipdb> h

Documented commands (type help <topic>):
========================================
EOF    cl         disable  interact  next    psource  rv           undisplay
a      clear      display  j         p       q        s            unt      
alias  commands   down     jump      pdef    quit     skip_hidden  until    
args   condition  enable   l         pdoc    r        source       up       
b      cont       exit     list      pfile   restart  step         w        
break  continue   h        ll        pinfo   return   tbreak       whatis   
bt     d          help     longlist  pinfo2  retval   u            where    
c      debug      ignore   n         pp      run      unalias    

Miscellaneous help topics:
==========================
exec  pdb

ipdb> s
0.1
0.1111111111111111
0.125
0.14285714285714285
0.16666666666666666
0.2
0.25
0.3333333333333333
0.5
1.0
---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
<ipython-input-8-a9361fd1acbd> in <module>
      8         print_endline(i)
      9 
---> 10 main()

<ipython-input-8-a9361fd1acbd> in main()
      6 def main() -> None:
      7     for i in range(10, -10, -1):
----> 8         print_endline(i)
      9 
     10 main()

<ipython-input-8-a9361fd1acbd> in print_endline(i)
      2 
      3 def print_endline(i: int) -> None:
----> 4     print(1.0 / i)
      5 
      6 def main() -> None:

ZeroDivisionError: float division by zero
In [11]:
import pixiedust
In [10]:
pixiedust.optOut()
Pixiedust will not collect anonymous install statistics.
In [ ]:
%%pixie_debugger

def print_endline(i: int) -> None:
    print(1.0 / i)

def main() -> None:
    for i in range(10, -10, -1):
        print_endline(i)

main()
Hey, there's something awesome here! To see it, open this notebook outside GitHub, in a viewer like Jupyter

Ca ne marche pas chez moi, ça affiche des codes couleurs ANSI non interprétés (16/02/2021).

In [14]:
def print_endline(i: int) -> None:
    print(1.0 / i)

def main() -> None:
    for i in range(10, -10, -1):
        print_endline(i)

main()
0.1
0.1111111111111111
0.125
0.14285714285714285
0.16666666666666666
0.2
0.25
0.3333333333333333
0.5
1.0
---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
<ipython-input-14-9bb48f270e40> in <module>
      6         print_endline(i)
      7 
----> 8 main()

<ipython-input-14-9bb48f270e40> in main()
      4 def main() -> None:
      5     for i in range(10, -10, -1):
----> 6         print_endline(i)
      7 
      8 main()

<ipython-input-14-9bb48f270e40> in print_endline(i)
      1 def print_endline(i: int) -> None:
----> 2     print(1.0 / i)
      3 
      4 def main() -> None:
      5     for i in range(10, -10, -1):

ZeroDivisionError: float division by zero

Conclusion

C'est cool !