Live data from Hacker News

Node.js and Python Interoperability

fridgerator.github.io

1–10 of 22 posts

Re: Node.js and Python Interoperability

#3
post #2

I recently did something similar with Tcl (instead of Python) and Duktape (instead of V8): https://rkeene.dev/js-repl/ All the Tcl runtime is in the "runtime" object, so like "runtime.puts('Hello World')" or "runtime.expr('2 128')", etc It was a lot of fun

Tcl is one of those languages that feel special once you get to know it. In a good way! It’s like a command prompt for actual code. I don’t know how to explain it any better.

Re: Node.js and Python Interoperability

#4
post #3
post #2

I recently did something similar with Tcl (instead of Python) and Duktape (instead of V8): https://rkeene.dev/js-repl/ All the Tcl runtime is in the "runtime" object, so like "runtime.puts('Hello World')" or "runtime.expr('2 128')", etc It was a lot of fun

Tcl is one of those languages that feel special once you get to know it. In a good way! It’s like a command prompt for actual code. I don’t know how to explain it any better.

I'm not sure I got to know Tcl properly. I needed to use it to interact with an electronics design tool in order to extract information about a design, and so most of what I learned was from the tool's documentation about how to use its API, and some random Stack Overflow for specific questions.

Anyway, Tcl felt very much like an 80's interpreted language to me. It seemed like every data structure was built on top of strings, and every statement was being run through eval().

Re: Node.js and Python Interoperability

#5
I've worked the opposite way: calling Javascript from Python, using PyV8. It worked okay enough, but it felt super fragile. We only used it to run a tiny bit of client-side code on the server. I wouldn't want to have a large project where Javascript and Python interact heavily.

Re: Node.js and Python Interoperability

#6
post #5

I've worked the opposite way: calling Javascript from Python, using PyV8. It worked okay enough, but it felt super fragile. We only used it to run a tiny bit of client-side code on the server. I wouldn't want to have a large project where Javascript and Python interact heavily.

I have just taken to running server and talking over http whenever I want two languages to interface. It’s slower but it’s pretty much bulletproof.

Re: Node.js and Python Interoperability

#8

I'm having the requirement to work with Node and Python now. I write my webapps in node but have data analytics scripts written in python to be invoked. I'm planning to use [python-shell - npm]( https://www.npmjs.com/package/python-shell )

Have you considered GraalVM? You can run both languages inside the same managed runtime (JVM), sharing the same data structures, inlining across language boundaries, and debug both with Chrome Dev Tools.

Re: Node.js and Python Interoperability

#9
post #4
post #3

Earlier quoted context omitted.

Tcl is one of those languages that feel special once you get to know it. In a good way! It’s like a command prompt for actual code. I don’t know how to explain it any better.

I'm not sure I got to know Tcl properly . I needed to use it to interact with an electronics design tool in order to extract information about a design, and so most of what I learned was from the tool's documentation about how to use its API, and some random Stack Overflow for specific questions. Anyway, Tcl felt very much like an 80's interpreted language to me. It seemed like every data structure was built on top o…

I haven't used Tcl in years, but you are right about strings, actually the goal is that every data type is implicitly marshalled into string and vice versa.

As for the eval you need to keep discipline there is difference whether you use [] {} or "".

The magic about the language is that it has no statements, for example you are missing try/catch? You can implement it your own: http://code.activestate.com/recipes/68396-try-catch-finally/

Re: Node.js and Python Interoperability

#10
I was once trying to do something even crazier: exposing full python accessibility to node.js, using proxies. So that you can use python objects and functions as native javascript objects and functions. It is feasible because the languages and runtimes share a number of common designs.

There were several tough things however. The first was error handling. Yes you can catch exceptions in native code and convert it to exceptions in the other language, but it's not straightforward to keep stacktraces. The second was circular references between runtimes. Since references across boundaries are global, garbage collector on either side could not reclaim circularly referenced objects. Although this could be resolved by manually breaking up the circle, it could be better to have weak references. (Or maybe other utilities, idk what would be more elegant.) The third was that js has no operator overloading, so I had to use .__add__() for example to call the python add operator.

One line example: https://github.com/swordfeng/pyjs/blob/master/test/jsobject.... It's a toy project I did years ago and not even compiling now. Also I was wondering if anyone really need to do things in this way, given there are bunch of popular and stable RPC libraries. But I was happy to learn something about underlying cpython and v8 from it.

Post reply on HN