Caught out by python/web2py syntax

36 views
Skip to first unread message

Carl Hunter Roach

unread,
May 16, 2017, 10:38:13 AM5/16/17
to web2py-users
I had (something like) the following code:

In db.py

a table called "point"

In a controller:

    # points is a list of dicts defining rows in table point
    for point in points: 
        db.point.insert(**point)

The code would disappear inside db.point.insert without throwing an exception. The table point would receive a row before the crash.

All I needed to do was avoid the loop increment variable name 'point' clashing with the table name point 'point' but I thought I'd just document my error here in case others come across something similar.

This refers to a GAE-based project.

Anthony

unread,
May 16, 2017, 12:20:57 PM5/16/17
to web2py-users
    # points is a list of dicts defining rows in table point
    for point in points: 
        db.point.insert(**point)

The code would disappear inside db.point.insert without throwing an exception.

It's not clear what the above sentence means.
 
The table point would receive a row before the crash.

What do you mean by "crash"? A web2py ticket?
 
All I needed to do was avoid the loop increment variable name 'point' clashing with the table name point 'point'

The Python code you have shown indicates no "clash" -- there is only one "point" variable in the code, and it does not conflict with the table name, which is an attribute of the db object (i.e., db.point). There must have been something else going on, but it is not even clear what problem you were having.

Anthony

Carl Hunter Roach

unread,
May 16, 2017, 1:05:22 PM5/16/17
to web2py-users
Sorry about the term "crash". "hang" is more accurate. No ticket is issued and the function db.point.insert does not return although an entry is made into my GAE data store.

The the following code works without hanging:

    for a_point in points:
       db.point.insert(**as_point)

I also realise that there was only one "point" variable in the code and it should not conflict with the table name. That knowledge stood between me and the issue for quite some time :)

If I place the hanging code inside a try/except no exception is caught.

--
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/zZ1g2S0ywVs/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.
--
Carl D Hunter Roach
Bisham Barn Owl Group
Runnymede Ringing Group
Reply all
Reply to author
Forward
0 new messages