python-2.6.2 Exception: TypeError: "'NoneType' object is not callable" in ignored
Dave Angel
davea at ieee.org
Sun Jun 14 21:39:19 EDT 2009
Poor Yorick wrote:
> <div class="moz-text-flowed" style="font-family: -moz-fixed">The
> following code produces an error (python-2.6.2). Either of the following
> eliminates the error:
>
> . assign something besides mod1 (the newly-created module) to d1
>
> . remove the call to shelve.open
>
> Why is there an error produced in the first place? What is the
> interaction
> between d1, mod1, and shelve about? This code runs without error in
> python-3.1
>
> $ cat test1.py
> import test2
> newmodule = test2.load()
>
> $ cat test2.py
>
> import imp
> import shelve
>
> def load():
> text='import test2\n'
> text += '''print('hello from test3')\n'''
> code = compile(text,'<fake>', 'exec')
> mod1 = imp.new_module('newmodule')
>
> newdict = mod1.__dict__
> #newdict = {}
>
> exec(code,newdict)
> mod1
> mode = mod1
> d1['unique'] = mod1
> #d1['unique'] = ''
> return mod1
>
> print('hello from test2')
> d1 = {}
> cache = shelve.open('persist')
>
> $ python2.6 test1.py
> hello from test2
> hello from test3
> Exception TypeError: "'NoneType' object is not callable" in ignored
> Exception TypeError: "'NoneType' object is not callable" in ignored
>
You don't need all those lines to trigger these exception messages. All
you need in test1.py is the import statement. And in test2.py:
import shelve
cache = shelve.open('persist')
To cure it, just close the cache:
cache.close()
I don't have any idea what the exception means, but this seems like a
logical thing, to close it.
More information about the Python-list
mailing list