I’m gonna try to explain this issue in a succinct way, but feel free to ask for more details if you want it.
I’m using the following code to get the card ids stored in a table in a sqlite3 file:
info = cursor.execute(
'''SELECT cid FROM events''' ).fetchall()
This code returns the following list of tuples:
[(None,), (None,), (None,), (None,), (None,), (None,), ('1631565234935',), ('1582147898059',)]
In order to get each one of the values in this list I use:
info = [(None,), (None,), (None,), (None,), (None,), (None,), ('1631565234935',), ('1582147898059',)]
for x in info:
for y in x:
print(y)
Which returns:
>>> info = [(None,), (None,), (None,), (None,), (None,), (None,), ('1631565234935',), ('1582147898059',)]
... for x in info:
... for y in x:
... print(y)
None
None
None
None
None
None
1631565234935
1582147898059
However, if I try to run the same code inside a function, it returns no output:
def getCid(self):
info = [(None,), (None,), (None,), (None,), (None,), (None,), ('1631565234935',), ('1582147898059',)]
for x in info:
for y in x:
print(y)
like this:
>>> def getCid(self):
... info = [(None,), (None,), (None,), (None,), (None,), (None,), ('1631565234935',), ('1582147898059',)]
... for x in info:
... for y in x:
... print(y)
<no output>
I’ve also tried:
info = [(None,), (None,), (None,), (None,), (None,), (None,), ('1631565234935',), ('1582147898059',)]
for x in info:
for y in x:
print(y)
def getCid(self):
print(y)
Which works fine in the Debug Console:
However, if I use the following code and try to use the value of “y” to be executed inside the function, the add-on always returns the last value of the list.
info = cursor.execute(
'''SELECT cid FROM events''' ).fetchall()
for x in info:
for y in x:
cid = y
def notWorkingFunction():
(...)
if cmd == "display-cid":
(...).setText("cid:" + str(cid))
What I’m trying to achieve, instead, is: if I click one item, it will return the correspondent cid, if I click another item, it will return this item’s cid, and so on.
It’s also intriguing that I can perfectly get the values of the card’s ids inside another function in the same module
using:
def anotherFunction(content):
data = cursor.execute(
'''SELECT * FROM events ORDER by date(aGivenDate) %s''' % "ASC").fetchall()
for row in data:
variable = row[2]
(...)
cid = row[14]
(...)
content.stats += "<b title="+ str(cid) +">" + variable + "</b>"
(...)
What the function above does is that when I hover the mouse over the text it displays a tooltip showing the cid of the card related with that particular text, however, if I click on it, it only returns the last cid of the list (as I stated before), even if the text is not related to it.
Could you please point what’s wrong with my approach here?