convert python List to javascript array

Vineet Deodhar d_vineet at yahoo.com
Fri Sep 2 17:34:25 CEST 2011


Hi !
Within a web framework, I want want to pass a python sequence (list or tuple) to client-side javascript function as an array (javascript compatible)
e.g., I have this list:
L = ['spam', 'ham', 'eggs', 12, (13.63)]
What is the correct way to convert L to javascript array format? 

1) jsonify the list and pass it to javascript
(whether json format & javascript array are similar?)

OR
2) 
>> import array
>> y = array.array(i, L)
 then return y to javascript function
But the problem with this method is, it will give an array of basic values only.

OR
3) Any other alternative?

Thanks,
Vineet
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110902/892c620c/attachment.html>


More information about the Python-list mailing list