title: web2py: how to copy a python array into a javascript one
body: <p>I'm currently having an issue with getting javascript and python to communicate in web2py.</p>
  
  <p>controller:</p>
  
  <pre><code>def testDB():
          a=[]
          a.append('a')
          a.append('b')
          a.append('c')
          return dict(m=a)
  </code></pre>
  
  <p>(Eventually this will be replaced with an array of DB rows)
  Currently I'm trying to assign the values in m to an array in javascript. I've tried this a few ways:</p>
  
  <pre><code>var t="{{=m}}";
  </code></pre>
  
  <p>Returns about 43 meaningless characters. Then I tried:</p>
  
  <pre><code>var t= new Array(); var i=0;"{{q=0}}"
  "{{i=len(message)}}"
  i="{{=i}}";
  for(q=0;q&lt;i;q++,"{{q=q+1}}"){
  t[q]="{{m[q]}}";
  }
  </code></pre>
  
  <p>Which failed because the python q variable would reset every time the loop did, which is the heart of my problem.
  I also tried using pop:</p>
  
  <pre><code>for(q=0;q&lt;i;q++,"{{q=q+1}}"){
      alert("{{m.pop()}}");
      }
  </code></pre>
  
  <p>But the array keeps resetting again at the start of the loop, so it keeps showing the same variable.
  Is there a simpler way to copy the arrays, or to stop the python variables resetting, or even simply to plug the javascript q variable into "{{m[q]}}" instead?</p>
  
  <p>From what I've found, the problem comes from python being server side so you can't assign javascript values to it's variables, but I'm not sure what that has to do with the loop part of it (If I do the same outside a loop, the values do not reset). The common solution seems to be to use ajax or json, but I'd like to avoid that if possible. Thanks</p>