DAL Rows and Row from list and dict, respectively

52 views
Skip to first unread message

Lucas

unread,
Jan 11, 2026, 11:51:46 PMJan 11
to py4web
hello one and all,

isn't this possible?

from pydal.objects import Rows, Row
qFab = Rows([ Row({'word':'happy', 'letters':'fifnen',}), Row({'word':'day', 'letters':'jfinef',}), ]) 

and then:
for f in qFab:
    w, l = f.word, f.letters
    etc....

I seem to remember doing these sorts of things in web2py.
thank you in advance, Lucas

Alan Etkin

unread,
Jan 15, 2026, 6:40:58 AMJan 15
to py4web
HI

Have you tried it in a shell?, doesn't seem to be a documented feature

Regards

Alan

Massimo DiPierro

unread,
Jan 17, 2026, 10:56:27 PMJan 17
to py4web
I do not think this was every supported. What is the use case?

Lucas

unread,
Jan 26, 2026, 8:44:23 AMJan 26
to py4web
ok, to answer both questions.  so, normally, I would db().select() and of course Rows containing Row would return and pass to computations using that data.  but there were times when I generated Rows of Row on-the-fly and temporarily and pass that off to the same computational side.  so the latter is where I would use this on-the-fly Rows of Row to mimic that it came from the db and I wouldn't have to change the computational side.  it's a practical use, believe me.

and so I created a shell script side to test and this is that code:
BOF...
#!/usr/bin/env python
#coding: utf-8
#> xattr -d com.apple.quarantine pydal_row_rows.py
from pydal.objects import Row, Rows

print('opening words.. .')
words = [('the', 26380), ('and', 20367), ('of', 18240), ('to', 15560), ('in', 10501), ('you', 8890), ('a', 7734), ('for', 7691), ('he', 7152), ('lord', 7075), ('i', 6173), ]
print('opened.')

r = Row({'word':words[0][0], 'N':words[0][1]})
print(type(r), r)
print(r.word, r.N, r['word'], r['N'])

# print()
# print('looped.. .')
# qWords1 = Rows()
# for w in words:
# qWords1.append(Row({'word':w[0], 'N':w[1]}))
# print(type(qWords1), len(qWords1))
# for i, w in enumerate(qWords1):
# print(i, w.word, w.N, w['word'], w['N'])
# print('done.')

print()
print('comprehension.. .')
qWords2 = Rows([ Row({'word':w[0], 'N':w[1]}) for w in words ])
print(type(qWords2), len(qWords2))
for i, w in enumerate(qWords2):
print(i, w.word, w.N, w['word'], w['N'])
print('done.')

exit()
EOF.

the most interesting this is that Row seems to work fine in all 3 scenarios.  "comprehension" only works when the "looped" section is uncommented.  definite weird bug in there somewhere.

ok, thank you in advance and sorry for the delay in responding.  Lucas
Reply all
Reply to author
Forward
0 new messages