Another Book Correction Needed (5th ed P.369)

21 views
Skip to first unread message

REM

unread,
Aug 20, 2013, 12:47:29 PM8/20/13
to web...@googlegroups.com
There appears to be another error in the 5th Edition Web2Py book in Chapter 7 on P.369.

The issue is with the following code block:

def list_records():
    REGEX
= re.compile('^(\w+).(\w+).(\w+)\=\=(\d+)$')
    match
= REGEX.match(request.vars.query)
   
if not match:
        redirect
(URL('error'))
    table
, field, id = match.group(2), match.group(3), match.group(4)
    records
= db(db[table][field]==id).select()
   
return dict(records=records)

When the related action is run, we get the following error:

<type 'exceptions.NameError'> global name 're' is not defined

And referring to line 2 of the above function as being the source of the issue:

REGEX = re.compile('^(\w+).(\w+).(\w+)\=\=(\d+)$')

So, my question is: with what do we replace the "re" in the problem line?



Many thanks!




Alex

unread,
Aug 20, 2013, 1:46:07 PM8/20/13
to web...@googlegroups.com
seems like
import re
is missing at beginning of function.

Alex

Robert Moore

unread,
Aug 20, 2013, 1:55:42 PM8/20/13
to web...@googlegroups.com
Thanks, now it works.

Man, seems like learning this stuff would be a lot easier if I had already learned it. Then spotting/fixing these book errors would be a breeze.




--
 
---
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/V_0dYYN6B8E/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/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages