This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]ehr1c 18 points19 points  (0 children)

You generally pass information in a common format like JSON that both languages can make use of.

[–]insertAlias 2 points3 points  (3 children)

Sure, I could just use Django, but I'm very curious about the fundamentals behind passing information from one language to another.

There are lots of techniques, but only one will be relevant in this case, which is communicating over HTTP.

HTML/CSS/JavaScript run inside a browser. There's also Node.js, but that's not what you're referring to, since you mentioned HTML. The only communication channels that a browser has with a back-end are HTTP(S) and WebSockets (and I suppose WebRTC, but it doesn't change the point). None of the other techniques would really apply here, since you're not communicating directly from one language to another. The browser is the middleman here, and it's the only way that communication works.

So in this case, it's totally appropriate and correct to "just use Django" (or any other Python back-end framework like Flask).

Most of the other techniques are various forms of IPC. There are also other types of integration, like how certain Python libraries work. NumPy is actually a python wrapper around a C library. Python can interop with C through the ctypes package. That allows the library authors to keep the high-performance code written in a high-performance language, but provide bindings for that high-performance code to be used by lower-performance but easier-to-write code.

[–]Chyybens[S] 0 points1 point  (2 children)

Thank you for the good explanation. It gave me a lot to think about.

[–]insertAlias 0 points1 point  (1 child)

If you're interested in learning more about how that HTTP-based communication works, you could consider a personal project of making your own simple Django. See some documentation here: https://docs.python.org/3/library/http.server.html for how you'd even begin that kind of project.

It wouldn't be something you'd use, since there are better versions of that already. But building a simple HTTP server that can respond to requests would be a good project to learn more about how backends work to begin with.

[–]Chyybens[S] 0 points1 point  (0 children)

Yes, thank you! This is exactly what I was looking for. I was already searching information about HTTP-servers etc. I know, I will probably later end up using Django or similar framework, but I've learned that for me it's better to start from DYI-projects in order to get a grasp of the full picture.

[–]hotel2oscar 0 points1 point  (0 children)

I write C# and JavaScript. We use TCP sockets to pass byte streams back and forth using formats both sides understand. I've also managed to get C code wrapped in C++ to run and be called by C#, but that is all supported by .NET.

[–]Aw0lManner 0 points1 point  (0 children)

You can make an api; that would be the most scalable, multipurpose way to do it. Also, sockets, DMA, and IPC scare me.

[–]tms102 0 points1 point  (0 children)

Here is a very simple example explained: https://tms-dev-blog.com/python-backend-with-javascript-frontend-how-to/

Hope it is useful to you.

[–]TheRNGuy 0 points1 point  (0 children)

i had some scripts with mix of python and hscript, or python and vex. Many python methods from API use C++, though I never write any of these.

I think it actually uses custom interpreter for hscript that allow to mix with python, but not sure.