Class definition problem in a Python Script
I'm using a method to look up an object within a folder and returning that object. In some cases, however, the object isn't found. In all cases, I want to return an object as I do some checking to ensure that the object was indeed found. Unfortunately, my mechanism for doing so is giving me a "SyntaxError, Names starting with "_" are not allowed (__doc__)." Here is the code... def get_object_by_element_number(objList, given_element_number): class MyErrorClass: "Dummy class so something is returned (with an error indicator)" element_number = -1 found = 0 for obj in objList: if given_element_number = obj.element_number: found = 1 return obj if found == 0: error_obj = MyErrorClass return error_obj ------- Does anyone know what the problem is? At first, I thought it was a docstring problem, but I pulled the example out of the Python Tutorial (from python.org). Any hints? Thanks in advance, Ron
complaw@hal-pc.org writes:
... Unfortunately, my mechanism for doing so is giving me a "SyntaxError, Names starting with "_" are not allowed (__doc__)."
Here is the code...
def get_object_by_element_number(objList, given_element_number):
class MyErrorClass: "Dummy class so something is returned (with an error indicator)" element_number = -1
found = 0 for obj in objList: if given_element_number = obj.element_number: found = 1 return obj
if found == 0: error_obj = MyErrorClass return error_obj
I can do it without problem (replaced "error_obj = MyErrorClass" with "error_obj= MyErrorClass()"). Are you sure, the SyntaxError is inside this script? I expect problems when I would try to access the object in TTW code (no "SyntaxError" but an "Unauthorized" exception). I would probably go for the following solution: Provide security declarations that make "ZPublisher.HTTPRequest.Record" importable. Derive your class from "Record". Dieter
participants (2)
-
complaw@hal-pc.org -
Dieter Maurer