On Sunday, January 8, 2017 at 3:04:07 PM UTC-5, Terrence Brannon wrote:
>
> I attempted to simplify creation of the response.menu list of tuples by 
> the following function:
>
>
> def menu_item(menu_item_text, url, sub_menu=None, ignore=False):
>     # First element of tuple is the text of the meny item.
>     retval = list(menu_item_text)
>

The above is not the way to create a list with menu_item_text as a single 
item. The list() function iterates over the argument passed in and makes 
each element a list item. Because strings are iterable, it creates a list 
with each element being a single character in menu_item_text. Therefore, 
the fourth item in retval is always the fourth character in menu_item_text 
rather than the sub_menu. When the MENU helper gets to what it expects to 
be a submenu, it instead gets a single character, which of course cannot be 
unpacked via item[:3].

It's always a good idea to test the outputs of your functions as you 
develop them -- much easier to find bugs when you can isolate the effect to 
a small function.

Anthony

-- 
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 the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to