Giter Club home page Giter Club logo

py2nb's Introduction

py2nb: convert python scripts to jupyter notebooks

py2nb

convert python scripts to jupyter notebooks

Author

Will Handley

Version

1.0.0

Homepage

https://github.com/williamjameshandley/py2nb

PyPi location

Description

py2nb is a python package for converting python scripts with minimal markdown to jupyter notebooks.

Markdown cells are rendered from comments beginning with #|, splits between code cells are created by comment lines beginning with #-

nb2py converts from jupyter notebooks to python

Installation

Users can install using pip:

pip install py2nb

from source:

git clone https://github.com/williamjameshandley/py2nb
cd py2nb
python setup.py install

or for those on Arch linux it is available on the AUR

Example

If one has a script named example.py containing the code:

#| # Testing ipython notebook
#| This is designed to demonstrate a simple script that converts a script into
#| a jupyter notebook with a simple additional markdown format.
#|
#| Code by default will be put into code cells
#|
#| * To make a markdown cell, prefix the comment line with with '#|' or '# |'
#| * To split a code cell, add a line beginning with '#-' or '# -'

import matplotlib.pyplot as plt
import numpy

%matplotlib inline

#| Here is a markdown cell.
#| Maths is also possible: $A=B$
#|
#| There are code cells below, split by `'#-'`:

# | Here is another markdown cell

x = numpy.random.rand(5)

#-------------------------------

y = numpy.random.rand(4)
z = numpy.random.rand(3)

#| Here are some plots

x = numpy.linspace(-2,2,1000)
y = x**3
fig, ax = plt.subplots()
ax.plot(x,y)

# -------------------------------

# | Here is another plot

x = np.linspace(-np.pi, np.pi, 201)
fig, ax = plt.subplots()
ax.plot(x,np.sin(x))

then running

produces the notebook example.ipynb

To do

  • evaluation option for script produced
  • vim syntax highlighting for markdown code blocks

py2nb's People

Contributors

williamjameshandley avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.