Error in tutorial sample

Issue #12 resolved
Former user created an issue

here is the tutorial :

from CodernityDB.database import Database from CodernityDB.hash_index import HashIndex

class WithXIndex(HashIndex):

def __init__(self, *args, **kwargs):
    kwargs['key_format'] = 'I'
    super(WithXIndex, self).__init__(*args, **kwargs)

def make_key_value(self, data):
    a_val = data.get("x")
    if a_val is not None:
        return a_val, None
    return None

def make_key(self, key):
    return key

def main(): db = Database('/tmp/tut2') db.create() x_ind = WithXIndex(db.path, 'x') db.add_index(x_ind)

for x in xrange(100):

for y in xrange(100):

print db.get('x', 10, with_doc=True)

if name == 'main': main()

here is the error :

Traceback (most recent call last): File "C:/Python27/", line 39, in <module> main() File "C:/Python27/", line 27, in main db.add_index(x_ind) File "C:\Python27\lib\site-packages\codernitydb-0.4.2-py2.7.egg\CodernityDB\", line 331, in add_index ind_obj, name = self.write_index(new_index, _next, edit=False) File "C:\Python27\lib\site-packages\codernitydb-0.4.2-py2.7.egg\CodernityDB\", line 301, in write_index self._add_single_index(p, number, ind) File "C:\Python27\lib\site-packages\codernitydb-0.4.2-py2.7.egg\CodernityDB\", line 167, in _add_single_index code = getsource(index.class) File "C:\Python27\lib\", line 699, in getsource lines, lnum = getsourcelines(object) File "C:\Python27\lib\", line 688, in getsourcelines lines, lnum = findsource(object) File "C:\Python27\lib\", line 527, in findsource file = getsourcefile(object) File "C:\Python27\lib\", line 446, in getsourcefile filename = getfile(object) File "C:\Python27\lib\", line 410, in getfile raise TypeError('{!r} is a built-in class'.format(object)) TypeError: <module 'main' (built-in)> is a built-in class

The codernity code seems well installed. The previous example runs well and the speed is very good. Best regards


Comments (3)

  1. Codernity repo owner

    Thanks for the report,

    But it seems to be Windows related issue, the code from tutorial works perfectly fine on Linux environments.

    Obviously we will check it.

  2. Patrick Laffitte

    You ara welcome.

    There is a workaround :

    the create a error when you try to retreive the code of WithXIndex class because this class belongs to main program If you create an independant module for WithIXndex class and you run the main independly (only import the WithXIndex class ) the systems seems run well.

    Best regards


  3. Log in to comment