mercredi 20 janvier 2016

Is it possible to separate multiple values pulled in from a SQLite3 Row using Python?

I have a database row that links, as an example, the name Mike to the description blonde, short, glasses. Current, if I were to run person.description, it prints out like this:

" ""blonde""", 'short', 'glasses',

Is it possible to separate these values and eliminate the extra '"'s? Here are a few things I've tried:

    for i in person:
        for j in i['description']:
            print j

This returns each descriptive word character by character:

" 
"
"
b
l
o
n
d
e
"
"
"
,

Next I tried:

for i in plugins:
    print i['sets_kb_item']

This returned:

" ""blonde""",  'short',  'glasses', 

I've also tried this, just trying to get lucky:

    for i in person:
        for j in i:
            print j['description']

But this gave me a TypeError:

TypeError: 'int' object has no attribute '__getitem__'

Here is an example of a row in the sqlite database that I am querying:

Name:        Description:
Mike         'blonde', "" """"short"""""",  'glasses',"

And here is the query I'm using:

 cur = db.execute("select * from person where description like ?", (query,))

My end goal is to have output that prints something like:

Name: Mike
- blonde
- short
- glasses

Ultimately, I need to revisit just what the heck went on when I imported these values into my DB, but is there anything I can do until then?

Aucun commentaire:

Enregistrer un commentaire