I have several lists in sqlite rows as follows:
ROWID x
1 ['123', '1234', '12345',]
2 ['abc', 'abcd', 'abcde',]
3 ['1a2b3c', '1a2b3c4d', '1a2b3c4d5e',]
I would like to iterate over these items in a game that matches them with a user input, say when a user prints 123, it prints out the answer or gives a boolean value. The only problem is that when i print our items in row[1] or row[2] i get a none value, but is works well with row[0].
This is part of my code on the sqlite section.
def types():
location = ""
conn = sqlite3.connect("types.db")
c = conn.cursor()
c.execute('select * from types ORDER by X')
for rowid,X in c.execute("select rowid,X from types order by X"):
return row[:]
I have several lists in sqlite rows as follows:
ROWID x 1 ['123', '1234', '12345',] 2 ['abc', 'abcd', 'abcde',] 3 ['1a2b3c', '1a2b3c4d', '1a2b3c4d5e',]
def types(): location = "" conn = sqlite3.connect("types.db") c = conn.cursor() c.execute('select * from types ORDER by X') for rowid,X in c.execute("select rowid,X from types order by X"): return row[:]
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/dNtVIOucH9Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thanks for the input. Yes it is part of a web2py app game.I have about 1000 rows, but when a user types in the keyword(stored in any of the rows) i should get a boolean answer which for now displays the row(different code on this)
db.define_table('keywords',
Field('x', 'list:string'))
keyword = '123' # in reality, this is obtained via user input
match_row = db(db.keywords.x.contains('|%s|' % keyword)).select().first()
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/dNtVIOucH9Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
match_row = db(db.keywords.x.contains('|%s|' % keyword)).select().first(). This picks the first item in he list. How about a random search through the list without using select().first()?
2. In my code:
def types:
db = DAL('sqlite.storage.db')
db.define_table('types'
Field('body'))
rows = db(db.types.body.id>0)select()
for item in row:
item = item
return item.
I GET AN ERROR: NoneType item not iterable. I want the user to put in any data e.g. '123' and if boolean(True) it prints out the answer.I am using this code on a ython module imported to web2py and not in the controller. In my view: {{=item}}
Hi1. I note that the code:match_row = db(db.keywords.x.contains('|%s|' % keyword)).select().first(). This picks the first item in he list. How about a random search through the list without using select().first()?
db(db.keywords.x.contains('|%s|' % keyword)).select(orderby='<random>').first()
2. In my code:
def types:
db = DAL('sqlite.storage.db')
db.define_table('types'
Field('body'))
rows = db(db.types.body.id>0)select()
for item in row:
item = item
return item.
I GET AN ERROR: NoneType item not iterable. I want the user to put in any data e.g. '123' and if boolean(True) it prints out the answer.I am using this code on a ython module imported to web2py and not in the controller. In my view: {{=item}}
It might help if you spend a little more time with the web2py documentation to better understand how everything works together.
Anthony