Tuesday, May 21, 2024
 Popular · Latest · Hot · Upcoming
114
rated 0 times [  118] [ 4]  / answers: 1 / hits: 51944  / 10 Years ago, sun, march 23, 2014, 12:00:00

I want to convert some basic snippets to JavaScript, just pure Python I wrote myself to pure JavaScript. Is there any thing out there? Here the code.



items = init['items']

itemsKeyedById = {i[id]: i for i in items} # hard to convert.

for item in items:
if item[parents][0]['isRoot'] == False:
parent = itemsKeyedById[item[parents][0]['id']]

if children not in parent:
parent[children] = []
parent[children].append(item)

topLevelItems = [item for item in items if item[parents][0]['isRoot'] == True] # hard to convert.
try:
return json.dumps(topLevelItems[0]);
except:
return '[]'



@Davide: Sadly this question has been closed, otherwise I'd write an answer instead of a comment. The best way to do have python as client side these days is with https://github.com/qquick/Transcrypt



More From » python

 Answers
4

You can actually run a Python interpreter directly in JS thanks to emscripten.



The project is called empythoned:




Empythoned is a build script that uses Emscripten to compile CPython
for use in a browser. It attempts to compile the main interpreter as a
single small executable and the whole standard library as dynamically
loaded libraries.




but be warned:




The project is in its infancy. Right now the core interpreter works
very well, but many of the libraries either don't work at all or
contain various bugs.



[#71829] Friday, March 21, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
koltonadolfow

Total Points: 71
Total Questions: 118
Total Answers: 102

Location: Vietnam
Member since Sun, Oct 18, 2020
4 Years ago
;