1

In Python when i'm making a query to select everything from set row in sqlite, It works fine but the string that i append into a array look rather odd.

This is my array when I append the same data into my array but from at text file:

ORC
TROLL
WORGEN
DWARF

but if I try to do the same from the data i appended from my sqlite table i get this:

('ORC',)
('TROLL',)
('WORGEN',)
('DWARF',)

races = []

races = dbaction.execute("SELECT races FROM racetable;").fetchall()
for item in racetable:
  print(item)

How do I turn the print from sqlite into looking the same as the one from the text file? the problem is probably pretty simple, but i'm missing the keywords to google the answer i believe, because most posts are talking about unicode and utf-8

3 Answers 3

1

Item is array-like, try print(item[0])

Sign up to request clarification or add additional context in comments.

2 Comments

cheers that worked, what does it mean when something is array like?
It means you get not a single value as a response on your request but a set of values (in each item of races array, some sort of array of arrays), so you need to address to some specific value with the index. For example you could make the SQL request like SELECT races, pilots FROM racetable and get two values in each races item. Although you requested only one value, the result is anyway an array - with one element. So, you need to address to it using index.
1

SQLite returnsa tuple for every row, which makes sense when your query can return multiple columns. So to create your array, you could use:

races = [race[0] for race in dbaction.execute("SELECT races FROM racetable;").fetchall()]

using list comprehension or similar.

Comments

0

Result-set from database is two-dimensional tuple. The item is tuple, so give an index for accessing any particular element.

for item in racetable:
  print (item[0])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.