The meaning of these arguments?

I am using Anki flash card program which is written in Python. I want to write my first addition. I am new to Python. I am not a technical expert, but I have several years of experience jumping inside other people's code in Java, C ++, C #, etc.

A flash card shows a question, for example, "Capital of France?". When the "Show Answer" button is clicked, Anki displays the answer "Paris".

I want to take this text “Paris” before it appears.

I came to this point in Anki code. At this point, the map displays "Capital of France?". The answer is still empty. I think I want to be able to capture "val" (which, I think, "Paris") and use it in my expansion.

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

def _onTypedAnswer(self, val):
    self.typedAnswer = val        
    self._showAnswer()

I searched the search terms to find the meaning of this:

("typeans ? typeans.value : null", self._onTypedAnswer)

, , .

.


: .

Anki . , .


"webview":

def evalWithCallback(self, js, cb):
    self.page().runJavaScript(js, cb)

"" . "mw" ( " " )

init ""

def __init__(self, mw):
    self.mw = mw
    self.web = mw.web
+4
4

typeans ? typeans.value : null C/C++/C# (, , Java ), ()

if typans:
   return typeans.value
else:
   return null

("typeans ? typeans.value : null", self._onTypedAnswer) - , .

+1

, , .

, val , .

:

def _onTypedAnswer(self, val):
    self.typedAnswer = val
    myobj.answer = val
    # or call a method on myobj to break flow
    # myobj.method(val)
    self._showAnswer()
0

BTW, ( ) ? typeans.value: null:

typeans and typeans.value or None
0
self.web.evalWithCallback("typeans ? typeans.value : null", self._onTypedAnswer)

evalWithCallback : "typeans ? typeans.value : null" self._onTypedAnswer. , evalWithCallback :

def evalWithCallback(self, js, cb):
    self.page().runJavaScript(js, cb)

, evalWithCallback JavaScript. , (, ), , , , typeans ? typeans.value : null JavaScript, self._onTypedAnswer, , val, _onTypedAnswer, JS.

, " ", , val , (.. , ).

0

Source: https://habr.com/ru/post/1654667/


All Articles