DAL Rows and Row from list and dict, respectively

95 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

Lucas

unread,
Feb 13, 2026, 5:53:44 PMFeb 13
to py4web
perhaps,,, not interesting???

Massimo DiPierro

unread,
Feb 16, 2026, 2:38:25 PMFeb 16
to py4web
I think this is a bit too much magic. Also what comes from the DB depends on the db and whether or not the data is or is not there may produce different results. I would not recommend doing it. I am surprised it works/worked but I think it should (except perhaps for testing).

Lucas

unread,
Feb 16, 2026, 7:08:15 PMFeb 16
to py4web
I guess I'm not understanding.  I'm attempting to use the Row and Rows object independent of any database.  just fill and use them strictly from code.  I've got many reasons for doing this.  you did see that the script works when we uncomment the "looped" middle section and doesn't work when it is commented.  try it out and you'll see what I mean.  its quite peculiar.

Christian Varas

unread,
Feb 16, 2026, 8:54:38 PMFeb 16
to Lucas, py4web
In my understanding, Rows are not very different from a list containing dictionaries (or Row objects).

Since Rows introduce additional abstraction, internal state, and built-in methods—along with some runtime overhead compared to plain Python lists and dictionaries—what is the main advantage of working with a Rows object instead of using standard data structures?

Is there a significant benefit that makes this approach preferable?

greetings 


--
You received this message because you are subscribed to the Google Groups "py4web" group.
To unsubscribe from this group and stop receiving emails from it, send an email to py4web+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/py4web/f1766ff1-6e78-445a-b257-08873828cb13n%40googlegroups.com.

Lucas

unread,
Feb 16, 2026, 9:48:31 PMFeb 16
to py4web
not so much with Rows but definitely, yes, with Row.  where Row keys can be addressed using ['key'] as like in dict.  or, like .key as in SimpleNameSpace.  so Row gives the programmer the option of using both interchangeably and that is actually quite nice from a coding point of view.

and since Rows is an extension of Row, it just goes to consistency of use.

Lucas

unread,
Feb 17, 2026, 3:39:16 PMFeb 17
to py4web
another interesting point.  below is code, updated from above, with both the "looped" and the "comprehension" sections active.  the "looped" loads the list in natural order and the "comprehension" loads the list in the reverse.  but both Rows return their version in the natural order.  that should not be.  coupling that to the first script I submitted, Rows() does not create a new separate and independent instance of the object even though the two instances occupy separate memory spaces.

#!/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[::+1]:

qWords1.append(Row({'word':w[0], 'N':w[1]}))
print(type(qWords1), len(qWords1), 'addr:', hex(id(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[::-1] ])
print(type(qWords2), len(qWords2), 'addr:', hex(id(qWords2)))

for i, w in enumerate(qWords2):
print(i, w.word, w.N, w['word'], w['N'])
print('done.')

exit()

Dave S

unread,
Feb 17, 2026, 11:30:13 PM (14 days ago) Feb 17
to py4web
On Tuesday, February 17, 2026 at 12:39:16 PM UTC-8 Lucas wrote:
another interesting point.  below is code, updated from above, with both the "looped" and the "comprehension" sections active.  the "looped" loads the list in natural order and the "comprehension" loads the list in the reverse.  but both Rows return their version in the natural order.  that should not be.  coupling that to the first script I submitted, Rows() does not create a new separate and independent instance of the object even though the two instances occupy separate memory spaces.


FWIW, trying in web2py -S <app>, qWord2 is empty unless qWord1 is defined, and then has the same records.  The address of qWord1[0] and of qWord2[0] match.

Using the comprehension to make an array (foo = []) works as expected.

(Yes, I'm still in "studying mode" with py4web)

/dps

Lucas

unread,
Feb 19, 2026, 8:42:58 AM (12 days ago) Feb 19
to py4web
are you saying my script is wrong?  I don't understand what you're reporting.

but I added the hex(id(qWords1[0])) and hex(id(qWords2[0])) and you're correct that the memory addresses of both are the same and that shouldn't be either, right?  when declaring Row() in each section they should be a new instance in different memory slots.  so what is it with that too?  so weird.

Dave S

unread,
Feb 19, 2026, 3:49:15 PM (12 days ago) Feb 19
to py4web
On Thursday, February 19, 2026 at 5:42:58 AM UTC-8 Lucas wrote:
are you saying my script is wrong?  I don't understand what you're reporting.

I'm reporting that the comprehension by itself creates an empty Rows, and that if the loop is used to create another Rows, either before or after. the C-Rows then has the same contents.
 

but I added the hex(id(qWords1[0])) and hex(id(qWords2[0])) and you're correct that the memory addresses of both are the same and that shouldn't be either, right?  when declaring Row() in each section they should be a new instance in different memory slots.  so what is it with that too?  so weird.

I don't understand it either, but I peeked at the DAL code in web2py, and Rows are more iterators than structures.

/dps
Reply all
Reply to author
Forward
0 new messages