Within an except: block, how do I find the type of exception that was raised? In plain Python, it is sys.exc_type. In DTML, it's error_type. I do not see how to get it in a Python Script. I looked for the answer on the Web with no joy. A pointer to where I should have looked will be appreciated. Thank you. --kyler
Hi Kyler, On Wed, 24 Jul 2002 11:46:41 -0500 Kyler Laird <Kyler@Lairds.com> wrote:
Within an except: block, how do I find the type of exception that was raised? In plain Python, it is sys.exc_type. In DTML, it's error_type. I do not see how to get it in a Python Script.
I looked for the answer on the Web with no joy. A pointer to where I should have looked will be appreciated.
Thank you.
--kyler
I just went through this same frustration a few days ago. Dieter suggested checking the README tab for PythonScripts. <quote>
From the README.txt: The easiest way to make modules available to Python scripts on your site is to create a new directory in your Products directory containing an "__init__.py" file. At Zope startup time, this "product" will be imported, and any module assertions you make in the __init__.py will take effect. Here's how to do it:
o In your Products directory (either in lib/python of your Zope installation or in the root of your Zope install, depending on your deployment model), create a new directory with a name like "GlobalModules". o In the new directory, create a file named "__init__.py". o Edit the __init__.py file, and add calls to the 'allow_module' function (located in the Products.PythonScripts.Utility module), passing the names of modules to be enabled for use by scripts. o Restart your Zope server. After restarting, the modules you enabled in your custom product will be available to Python scripts. </quote> Here is my __init__.py file: # Global module assertions for Python scripts from Products.PythonScripts.Utility import allow_module allow_module('sys.exc_info') You can now access the error_type and error_value from a python script error_type = sys.exc_info()[0] error_value = sys.exc_info()[1] It still seems to me there should be a standard way to do this within Zope but this worked for me in a pinch. Jim Gallacher ~
On Thu, Jul 25, 2002 at 10:30:19AM -0400, Jim Gallacher wrote:
Here is my __init__.py file:
# Global module assertions for Python scripts from Products.PythonScripts.Utility import allow_module allow_module('sys.exc_info')
You can now access the error_type and error_value from a python script error_type = sys.exc_info()[0] error_value = sys.exc_info()[1]
Yes, I've been doing a lot of this stuff lately, but I had really hoped to avoid it.
It still seems to me there should be a standard way to do this within Zope but this worked for me in a pinch.
Indeed. Python's error handling mechanism is so graceful that it's a shame to discourage its use in Zope. Well, at least I can stop looking for an existing solution. You've saved me some searching. Thank you. --kyler
participants (2)
-
Jim Gallacher -
Kyler Laird