arq5x / gemini

a lightweight db framework for exploring genetic variation.
http://gemini.readthedocs.org
MIT License
317 stars 119 forks source link

add dict representation to GeminiRow #938

Closed matthdsm closed 4 years ago

matthdsm commented 4 years ago

Hi Brent,

is it possible to get a dict type return from an GeminiRow object using the existing code? Alternatively, would it be possible to add a __dict__ method to the class?

Thanks Matthias

brentp commented 4 years ago

you can probably get it via:

d = {k: gr[k] for k in gr.keys}
matthdsm commented 4 years ago

Hi Brent,

Thanks for the suggestion, but no dice:

  File "/Users/matdsmet/OneDrive - UGent/Projects/seqplorer_django/seqplorer/seqplorer_ui/views.py", line 149, in query
    print({k: row[k] for k in row.keys})
TypeError: 'method' object is not iterable

Any other suggestion? Thanks M

arq5x commented 4 years ago

Try: print({k: row[k] for k in row.keys()})

matthdsm commented 4 years ago

Agh, stupid mistake, didn't call the keys method. Silly me. Thanks for the tip!

I've had to make a small modification to the code though, the keys method is now:

def keys(self):
        return self.row.keys() + self.cache.keys()

which doesn't work in python3, since self.row.keys() is a list and self.cache.keys()is a dict_keys type list. Casting self.cache.keys() as a list like so list(self.cache.keys()) fixes this issue, which in turn fixes my issue!

Thanks for all the help. I'll open a PR with the fix. Cheers M