Menu

#1 NameError on index.cgi

open
nobody
None
5
2011-01-13
2011-01-12
No

The page displays the following error message when loaded:

NameError Python 2.3.4: /usr/bin/python
Wed Jan 12 12:01:21 2011

A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred.
/home/bsccoo5/public_html/kingman/web/internal/index.cgi
53
54 import utils
55 utils.wiki = Wiki('kwiki-data')
56 utils.wikiurl = request.rsplit('/', 1)[0] + '/kwiki'
57 date, meta, body = utils.wiki.get_page('front_page_links')
utils = <module 'utils' from '/home/bsccoo5/public_html/kingman/web/internal/utils.py'>, utils.wiki = None, Wiki = <class utils.Wiki>
/home/bsccoo5/public_html/kingman/web/internal/utils.py in __init__(self=<utils.Wiki instance>, root='kwiki-data')
700 record += ('',)
701 title, tags, date, files, old_ids = record
702 self.index[self.get_id(title)] = (
703 title, sorted(tags.split()), int(date),
704 files.split(), old_ids.split())
self = <utils.Wiki instance>, self.index = {}, self.get_id = <bound method Wiki.get_id of <utils.Wiki instance>>, title = 'Front page links', sorted undefined, tags = '', tags.split = <built-in method split of str object>, builtin int = <type 'int'>, date = '1276204250', files = '2010/1', files.split = <built-in method split of str object>, old_ids = '', old_ids.split = <built-in method split of str object>

NameError: global name 'sorted' is not defined
args = ("global name 'sorted' is not defined",)

Discussion

  • Ka-Ping Yee

    Ka-Ping Yee - 2011-01-12

    The 'sorted' function was introduced in Python 2.4, and it looks like you're running Python 2.3. Upgrading to a newer version of Python should fix this problem.

     
  • BSC Webmaster

    BSC Webmaster - 2011-01-13

    The problem seems to have been that we were running Python 2.3.4 which does not contain the sorted() function in the __builitins__ list. Ping sent over a script to create a sorted() function and [I think] add it to the builtins. However, I got a different error focusing on the last line below:

    if not hasattr(__builtins__, 'sorted'):
    def sorted(iterable):
    items = list(iterable)
    items.sort()
    return items
    __builtins__.sorted = sorted

    Instead of using this script, I found a different replacement that essentially does the same thing in a different way, which seemed to work. I'm not sure what the problem with the first one was, but here's the working one:

    if not hasattr(__builtins__, "sorted"):
    def sorted(seq):
    result = [ x for x in seq ]
    result.sort()
    return result

     
  • BSC Webmaster

    BSC Webmaster - 2011-01-13
    • priority: 8 --> 5
     

Log in to post a comment.

MongoDB Logo MongoDB