Meaning of these arguments?
<p>I use a flashcard program called Anki, which is written in Python. I want to write my first add-on. I'm new to Python. I'm not a techie, but I have a few years experience of jumping around inside other people's code in Java, C++, C#, and so on.</p>

<p>The flash card shows a question, for example "Capital of France?". When the "Show Answer" button is pressed, Anki displays the answer "Paris".</p>

<p>I want to grab this text "Paris", before it's shown.</p>

<p>I've arrived at this point in the Anki code. At this instant, the card shows "Capital of France?". The answer is still blank. I think I want to be able to grab  "val" (which I think is "Paris") and use it in my add-on.</p>

<pre><code>def _getTypedAnswer(self):
    self.web.evalWithCallback("typeans ? typeans.value : null", self._onTypedAnswer)

def _onTypedAnswer(self, val):
    self.typedAnswer = val        
    self._showAnswer()
</code></pre>

<p>I've been googling to try to find the meaning of this:</p>

<pre><code>("typeans ? typeans.value : null", self._onTypedAnswer)
</code></pre>

<p>I have access to all the code, and I can provide any code that might be useful to responders.</p>

<p>Thanks.</p>

<hr>

<p>Added: after questions from responders.</p>

<p>Anki can be run on a computer or on the internet. All the results of studying cards are synced, so there's no difference between one method or the other as far as the end user is concerned.</p>

<hr>

<p>From the "webview" class:</p>

<pre><code>def evalWithCallback(self, js, cb):
    self.page().runJavaScript(js, cb)
</code></pre>

<hr>

<p>The "reviewer" class shows the questions and answers. The reviewer window is "mw" (for "main window")</p>

<p>Here's the init statement for class "reviewer"</p>

<pre><code>def __init__(self, mw):
    self.mw = mw
    self.web = mw.web
</code></pre>

<pre><code>self.web.evalWithCallback("typeans ? typeans.value : null", self._onTypedAnswer)
</code></pre>

<p>This just calls the <code>evalWithCallback</code> method with two arguments: the string <code>"typeans ? typeans.value : null"</code> and the method object <code>self._onTypedAnswer</code>.  You can see what <code>evalWithCallback</code> does with this from your posted code:</p>

<pre><code>def evalWithCallback(self, js, cb):
    self.page().runJavaScript(js, cb)
</code></pre>

<p>So <code>evalWithCallback</code> takes the string and runs it as JavaScript.  It's not clear from this exactly how the callback is called (for instance, what arguments it will be called with), but the essence of what the code does is it executes the string <code>typeans ? typeans.value : null</code> as JavaScript and then calls the function <code>self._onTypedAnswer</code>.  My guess would be that the <code>val</code> argument passed to <code>_onTypedAnswer</code> will be the result of the evaluating the JS expression.</p>

<p>Incidentally, judging from the name "typed answer", I would guess that <code>val</code> is not the correct answer to the question, but rather the user's guess (i.e., a value the user typed in).</p>

python anki