Sharing Variables Between Python & Node.js in Jupyter Notebooks

They live apart and speak different languages, but these variables hold common values

!pip install pixiedust_node
import pixiedust_node
%%node
console.log("Today's date is", new Date());
npm.install( ('request', 'request-promise') )
%%node
const request = require('request-promise');
request.get('http://www.google.com').then(print);
Share Python and Node.js variables in multiple directions. Photo by Brendan Church on Unsplash

Sharing variables (shariables?)

a = 'hello'
b = 2
c = False
d = {'x':1, 'y':2}
e = 3.142
f = [{'a':1}, {'a':2}, {'a':3}]
%%node
console.log(a, b, c, d, e, f);
// hello 2 false {y:2, x:1} 3.142 [{ a:1 }, { a:2 }, { a:3 }]
%%node
var i = 'world';
var j = 3;
var k = true;
var l = { z:99 }
var m = 2.7182;
var n = ['apples', 'oranges'];
print(i,j,k,l,m,n)
# (u'world', 3, True, {u'z': 99}, 2.7182, [u'apples', u'oranges'])
%%node
var googlehomepage = '';
request.get('http://www.google.com').then(function(data) {
googlehomepage = data;
print('Fetched Google homepage');
});

How to upgrade

!pip --upgrade pixiedust_node

Why do this?

--

--

Things we made with data at IBM’s Center for Open Source Data and AI Technologies.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store