File: recursive.py

package info (click to toggle)
pycallgraph 1.1.3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 416 kB
  • sloc: python: 1,925; makefile: 47
file content (30 lines) | stat: -rwxr-xr-x 577 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python
"""
This example demonstrates a simple recursive call.
"""

from pycallgraph2 import PyCallGraph
from pycallgraph2.output import GraphvizOutput


def factorial(n):
    if n == 1:
        return 1
    return n * factorial(n - 1)


def main():
    graphviz = GraphvizOutput()
    graphviz.output_file = 'recursive.png'

    with PyCallGraph(output=graphviz):
        try:
            for a in xrange(1, 10):
                factorial(a)
        except:
            for a in range(1, 10):
                factorial(a)


if __name__ == '__main__':
    main()