##// END OF EJS Templates
Cast environment variable key to bytes for Python 2 as well
Cast environment variable key to bytes for Python 2 as well

File last commit:

r18596:2d590459
r18951:3c85dd7f
Show More
nbexamples.py
104 lines | 2.3 KiB | text/x-python | PythonLexer
MinRK
copy nbformat.v3 to v4
r18568 # -*- coding: utf-8 -*-
import os
from base64 import encodestring
MinRK
no longer need separate v4.compose...
r18575 from ..nbbase import (
MinRK
remove heading cells in v4
r18596 new_code_cell, new_markdown_cell, new_notebook,
MinRK
first complete pass on v4...
r18573 new_output, new_raw_cell
MinRK
copy nbformat.v3 to v4
r18568 )
# some random base64-encoded *text*
png = encodestring(os.urandom(5)).decode('ascii')
jpeg = encodestring(os.urandom(6)).decode('ascii')
MinRK
first complete pass on v4...
r18573 cells = []
cells.append(new_markdown_cell(
MinRK
copy nbformat.v3 to v4
r18568 source='Some NumPy Examples',
))
MinRK
first complete pass on v4...
r18573 cells.append(new_code_cell(
source='import numpy',
MinRK
s/prompt_number/execution_count in nbformat 4
r18587 execution_count=1,
MinRK
copy nbformat.v3 to v4
r18568 ))
MinRK
first complete pass on v4...
r18573 cells.append(new_markdown_cell(
MinRK
copy nbformat.v3 to v4
r18568 source='A random array',
))
MinRK
first complete pass on v4...
r18573 cells.append(new_raw_cell(
MinRK
copy nbformat.v3 to v4
r18568 source='A random array',
))
MinRK
remove heading cells in v4
r18596 cells.append(new_markdown_cell(
source=u'## My Heading',
MinRK
copy nbformat.v3 to v4
r18568 ))
MinRK
first complete pass on v4...
r18573 cells.append(new_code_cell(
source='a = numpy.random.rand(100)',
MinRK
s/prompt_number/execution_count in nbformat 4
r18587 execution_count=2,
MinRK
copy nbformat.v3 to v4
r18568 ))
MinRK
first complete pass on v4...
r18573 cells.append(new_code_cell(
source='a = 10\nb = 5\n',
MinRK
s/prompt_number/execution_count in nbformat 4
r18587 execution_count=3,
MinRK
copy nbformat.v3 to v4
r18568 ))
MinRK
first complete pass on v4...
r18573 cells.append(new_code_cell(
source='a = 10\nb = 5',
MinRK
s/prompt_number/execution_count in nbformat 4
r18587 execution_count=4,
MinRK
copy nbformat.v3 to v4
r18568 ))
MinRK
first complete pass on v4...
r18573 cells.append(new_code_cell(
source=u'print "ünîcødé"',
MinRK
s/prompt_number/execution_count in nbformat 4
r18587 execution_count=3,
MinRK
copy nbformat.v3 to v4
r18568 outputs=[new_output(
MinRK
first complete pass on v4...
r18573 output_type=u'execute_result',
MinRK
move mime-bundle data to rich output.data...
r18589 data={
MinRK
first complete pass on v4...
r18573 'text/plain': u'<array a>',
'text/html': u'The HTML rep',
'text/latex': u'$a$',
'image/png': png,
'image/jpeg': jpeg,
'image/svg+xml': u'<svg>',
'application/json': {
'key': 'value'
},
'application/javascript': u'var i=0;'
},
MinRK
s/prompt_number/execution_count in nbformat 4
r18587 execution_count=3
MinRK
copy nbformat.v3 to v4
r18568 ),new_output(
output_type=u'display_data',
MinRK
move mime-bundle data to rich output.data...
r18589 data={
MinRK
first complete pass on v4...
r18573 'text/plain': u'<array a>',
'text/html': u'The HTML rep',
'text/latex': u'$a$',
'image/png': png,
'image/jpeg': jpeg,
'image/svg+xml': u'<svg>',
'application/json': {
'key': 'value'
},
'application/javascript': u'var i=0;'
},
MinRK
copy nbformat.v3 to v4
r18568 ),new_output(
MinRK
first complete pass on v4...
r18573 output_type=u'error',
MinRK
copy nbformat.v3 to v4
r18568 ename=u'NameError',
evalue=u'NameError was here',
traceback=[u'frame 0', u'frame 1', u'frame 2']
),new_output(
output_type=u'stream',
MinRK
first complete pass on v4...
r18573 text='foo\rbar\r\n'
MinRK
copy nbformat.v3 to v4
r18568 ),new_output(
output_type=u'stream',
MinRK
mv stream.stream > stream.name in nbformat.v4...
r18576 name='stderr',
MinRK
first complete pass on v4...
r18573 text='\rfoo\rbar\n'
MinRK
copy nbformat.v3 to v4
r18568 )]
))
MinRK
first complete pass on v4...
r18573 nb0 = new_notebook(cells=cells,
metadata={
'language': 'python',
}
MinRK
copy nbformat.v3 to v4
r18568 )