How can I "from __future__ import nested_scopes" in python scripts?
Hi All, I'm using Zope2.4 beta with Python 2.1 and I want to use the nest_scope functionality. However when I add the prerequisite statement: from __future__ import nested_scopes at the top of my python script it gives me an "ImportError" and "unauthorized" message. By default the nested scopes are not included. How do I this work? Jelle --
jelle wrote:
I'm using Zope2.4 beta with Python 2.1 and I want to use the nest_scope functionality. However when I add the prerequisite statement:
from __future__ import nested_scopes
at the top of my python script it gives me an "ImportError" and "unauthorized" message.
You don't have to. Starting in Zope 2.4.0a1, Nested scopes are always turned on. Shane
Hi Shane, I had hoped that to be true but the following code snippet fails in Python 2.1 unless I add the "__future__" import and always fails in Zope 2.4beta. By removing one of the "echoAlpha()" calls from either "echoBeta()" or "echoDelta()" and the Zope python script works. ---start Zope python script--- def echoAlpha(): return 'alpha.' def echoBeta(): return 'beta.' + echoAlpha() def echoDelta(): return 'delta.' + echoAlpha() print echoAlpha() print echoBeta() print echoDelta() return printed ---end Zope python script--- A similar "pure" python script follows: ---start python 2.1 code--- def checknestedscope(): def echoAlpha(): return 'alpha.' def echoBeta(): return 'beta.' + echoAlpha() def echoDelta(): return 'delta.' + echoAlpha() print echoAlpha() print echoBeta() print echoDelta() checknestedscope() ---end python 2.1 code--- I can get the "pure" python script to work by added the "__future__" import. Any ideas? Jelle On Tue, 26 Jun 2001, Shane Hathaway wrote:
jelle wrote:
I'm using Zope2.4 beta with Python 2.1 and I want to use the nest_scope functionality. However when I add the prerequisite statement:
from __future__ import nested_scopes
at the top of my python script it gives me an "ImportError" and "unauthorized" message.
You don't have to. Starting in Zope 2.4.0a1, Nested scopes are always turned on.
Shane
--
On Tue, 26 Jun 2001, jelle wrote:
I had hoped that to be true but the following code snippet fails in Python 2.1 unless I add the "__future__" import and always fails in Zope 2.4beta. By removing one of the "echoAlpha()" calls from either "echoBeta()" or "echoDelta()" and the Zope python script works.
Aha--there is a bug in there. It's as if using a name "consumes" it so that later functions can't use it. I'm sure this is a bug in the compiler package. Now that it's identified it shouldn't be hard to track down. Thanks for the test case! Shane
I'm using Zope2.4 beta with Python 2.1 and I want to use the nest_scope functionality. However when I add the prerequisite statement:
from __future__ import nested_scopes
at the top of my python script it gives me an "ImportError" and "unauthorized" message.
By default the nested scopes are not included.
How do I this work?
One approach would be to create a Python "product". In lib/python/Products create a new directory with a single __init__.py file containing only: from __future__ import nested_scopes After restarting, nested scopes should be enabled. Hope this helps! Brian Lloyd brian@digicool.com Software Engineer 540.371.6909 Digital Creations http://www.digicool.com
Hi Brian, I tried your suggestion by adding the "from __future__ import nested_scopes" statement to a database adapter product that I'm currently using. There doesn't seem to be a change with nested scope failure when I restarted Zope. Perhaps I mis-understood your instructions. Do I need a dedicated product specifically for nested scopes or a product for my script or will the "__future__" import in any product activate the behaviour. The last option doesn't seem to work with the sample script code in the previous post. Thanks Jelle On Tue, 26 Jun 2001, Brian Lloyd wrote:
I'm using Zope2.4 beta with Python 2.1 and I want to use the nest_scope functionality. However when I add the prerequisite statement:
from __future__ import nested_scopes
at the top of my python script it gives me an "ImportError" and "unauthorized" message.
By default the nested scopes are not included.
How do I this work?
One approach would be to create a Python "product". In lib/python/Products create a new directory with a single __init__.py file containing only:
from __future__ import nested_scopes
After restarting, nested scopes should be enabled.
Hope this helps!
Brian Lloyd brian@digicool.com Software Engineer 540.371.6909 Digital Creations http://www.digicool.com
--
participants (3)
-
Brian Lloyd -
jelle -
Shane Hathaway