File: nbexamples.py

package info (click to toggle)
ipython 2.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 28,032 kB
  • ctags: 15,433
  • sloc: python: 73,792; makefile: 428; sh: 297
file content (109 lines) | stat: -rw-r--r-- 2,296 bytes parent folder | download | duplicates (6)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import os
from base64 import encodestring

from ..nbbase import (
    NotebookNode,
    new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output,
    new_metadata, new_author
)

# some random base64-encoded *bytes*
png = encodestring(os.urandom(5))
jpeg = encodestring(os.urandom(6))

ws = new_worksheet(name='worksheet1')

ws.cells.append(new_text_cell(
    u'html',
    source='Some NumPy Examples',
    rendered='Some NumPy Examples'
))


ws.cells.append(new_code_cell(
    input='import numpy',
    prompt_number=1,
    collapsed=False
))

ws.cells.append(new_text_cell(
    u'markdown',
    source='A random array',
    rendered='A random array'
))

ws.cells.append(new_code_cell(
    input='a = numpy.random.rand(100)',
    prompt_number=2,
    collapsed=True
))

ws.cells.append(new_code_cell(
    input='print a',
    prompt_number=3,
    collapsed=False,
    outputs=[new_output(
        output_type=u'pyout',
        output_text=u'<array a>',
        output_html=u'The HTML rep',
        output_latex=u'$a$',
        output_png=png,
        output_jpeg=jpeg,
        output_svg=u'<svg>',
        output_json=u'json data',
        output_javascript=u'var i=0;',
        prompt_number=3
    ),new_output(
        output_type=u'display_data',
        output_text=u'<array a>',
        output_html=u'The HTML rep',
        output_latex=u'$a$',
        output_png=png,
        output_jpeg=jpeg,
        output_svg=u'<svg>',
        output_json=u'json data',
        output_javascript=u'var i=0;'
    ),new_output(
        output_type=u'pyerr',
        etype=u'NameError',
        evalue=u'NameError was here',
        traceback=[u'frame 0', u'frame 1', u'frame 2']
    )]
))

authors = [new_author(name='Bart Simpson',email='bsimpson@fox.com',
           affiliation=u'Fox',url=u'http://www.fox.com')]
md = new_metadata(name=u'My Notebook',license=u'BSD',created=u'8601_goes_here',
    modified=u'8601_goes_here',gistid=u'21341231',authors=authors)

nb0 = new_notebook(
    worksheets=[ws, new_worksheet(name='worksheet2')],
    metadata=md
)

nb0_py = """# -*- coding: utf-8 -*-
# <nbformat>2</nbformat>

# <htmlcell>

# Some NumPy Examples

# <codecell>

import numpy

# <markdowncell>

# A random array

# <codecell>

a = numpy.random.rand(100)

# <codecell>

print a

"""