Dictionary from sqlite3.Row and PyCharm unresolved reference

Mario Figueiredo marfig at gmail.com
Fri Feb 13 05:26:34 EST 2015


Currently i'm using the following code to transform a row fetched from an 
sqlite database into a dictionary property:

    def __init__(self, id_):
        self.id = id_
        self.data = None
        ...
        conn = sqlite3.connect('data')
        conn.row_factory = sqlite3.Row
        row = conn.execute(query, {'id': str(id_)}).fetchone()
        conn.close()

        if row:
            self.data = dict(zip(row.keys(), tuple(row)))

I have two questions:

  1. Is this an acceptable idiom for the construction of self.data dictionary,
      or do I have a better and more readable option?

  2. How can I stop PyCharm from giving me an unresolved reference warning
     at row.keys()? It's not a big deal, but slightly annoying. But I'd rather 
prefer
     a method that doesn't completely disable other valid cases.





More information about the Python-list mailing list