title: Invoke Brython function from JavaScript
body: <p>EDIT: <a href="https://groups.google.com/forum/?hl=en#!topic/brython/bGjUIFNH1ks" rel="nofollow noreferrer">Google Group post</a></p>
  
  <p>I'm playing with <a href="http://www.brython.info/" rel="nofollow noreferrer">Brython</a>.</p>
  
  <p>I'm trying to figure out how to execute Brython code from JavaScript.</p>
  
  <p><a href="http://www.brython.info/static_doc/en/jsobjects.html" rel="nofollow noreferrer">http://www.brython.info/static_doc/en/jsobjects.html</a> &lt;--  this looks like the relevant documentation page, but it seems to be lacking an example of invoking a Brython function from JavaScript.</p>
  
  <p>For my specific situation, I am listening to MIDI events (using <a href="https://github.com/cwilso/WebMIDIAPIShim" rel="nofollow noreferrer">https://github.com/cwilso/WebMIDIAPIShim</a>)</p>
  
  <p>I want Brython code to execute in response to a MIDI event received.</p>
  
  <p>Currently I'm trying:</p>
  
  <pre><code>function myMIDIMessagehandler( event ) 
  {
      if( brythonListener != null )
          brythonListener( event );
  </code></pre>
  
  <p>and Brython code:</p>
  
  <pre><code>&lt;script type="text/python3"&gt;
  
  from browser import document as doc, window, html
  
  def foo(event):
      print("BRYTHON!" + event);
  
  window.brythonListener = foo
  
  &lt;/script&gt;
  </code></pre>
  
  <p>But when I press a note on my midi keyboard, I get:</p>
  
  <p><a href="https://i.stack.imgur.com/6S6BY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6S6BY.png" alt="enter image description here"></a></p>
  
  <p>I don't know what to make of this error, and I'm not at all sure the approach is sound.</p>