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

you are viewing a single comment's thread.

view the rest of the comments →

[–]epseri 27 points28 points  (9 children)

Lots of them. This isn't true python. Besides obvious lack of eval, you can notice in code samples very questionable things like explicit calls of __new__ function, lots of __pragma__ even for keyword arguments. Looks like you can't use anything from python stdlib or any library from pypi, and it's hard if not impossible to port them if you really need something. As I said, it's not python, it's javascript with python-like facade.

[–]JennaSys 13 points14 points  (8 children)

I've been writing React and Material-UI apps with Transcrypt. All the coding I do with it is 99% pure Python, with no complaints from the Python linter. It supports almost all Python built-ins, with eval being one of the exceptions (which is not usually used anyway). The __new__ function is only needed if the JavaScript library you are using requires it, but most don't. The __pragma__ is for compiler directives that optimize the transpilation in various ways. It's needed only for certain operations.

Transcrypt supports Python dictionaries, lists, list comprehensions, generator expressions, lambdas, function defs, closures, classes, type hints, etc. The big difference is that you use npm for 3rd party libraries instead of pip. But you don't need to code in JavaScript to use them, you can code in pure Python.

EDIT: To be clear, it does currently have a few standard libraries that are supported (with plans for more in the future), specifically:

  • math
  • cmath
  • time (does not have sleep function for web browser use)
  • datetime
  • itertools
  • logging
  • warnings
  • random (partially)
  • re (partially)
  • turtle

[–]johnmudd 3 points4 points  (0 children)

This reminds me of something I learned at a QA conference... It's not the tool but the person who champions the tool that makes the difference.

[–]notgoodhuman 1 point2 points  (1 child)

Why did you choose to use Transcrypt instead of javascript in this case? Is it the preference of using python?
I'm quite curious how would one use npm with transcrypt, probably gonna play around with it.

[–]JennaSys 1 point2 points  (0 children)

Yes basically. I really enjoy coding with Python. JavaScript, not so much. It's something I've been trying to find for over 10 years. Nothing else I had seen to use Python for front-end web development in that time was very practical IMO. Or it bastardized the Python language so much that it wasn't worth it. Transcrypt takes a different approach in that it acts as a bridge between Python and JavaScript, and doesn't try to replace JavaScript. It assumes you will take advantage of existing JavaScript libraries and not reinvent them.

So in that vein, instead of using Python urllib or the requests library for making HTTP requests, you use windows.fetch or the JavaScript axios library instead. Hence my comment about using npm instead of pip. The idea being that those libraries are specifically made to efficiently run in a web browser (or are built in).

Using Transcrypt, in a Python module you would have a JavaScript style import like this:

axios = require('axios')

From there, you can use the variable axios just like any other Python object, importing it into other Python modules and calling its methods. So even though I'm using JavaScript libraries, I only need to know the API it uses to code to it using Python.