[Zope] TypeError: cannot add type "Python Method" to string
Ronald.Chichester@bakerbotts.com
Ronald.Chichester@bakerbotts.com
Mon, 10 Dec 2001 09:42:09 -0600
I am using a typical lookup routine in a python script to find information
about objects and return some of their properties. The method works great
when you are making a comparison of strings. E.g., the following code is
working just fine...
# Define a function to retrieve a particular class based on the element
number...
def get_class_by_title(objList, given_title):
found = 0
ret_list = []
# Run through the objects in the staff folder to see if there is a match
(with title)...
for obj in objList:
if found == 0:
if given_title == obj.title:
ret_list.append(obj.absolute_url) # List element 0
ret_list.append(obj.title) # List element 1
ret_list.append(obj.element_number) # List element 2
ret_list.append(obj.instance_type) # List element 3
ret_list.append(obj.derived_from) # List element 4
ret_list.append(obj.figure_number) # List element 5
found = 1 # Set flag on success...
# Return indicative values if the desired object was not found...
if found == 0:
ret_list.append('Error')
ret_list.append('Error')
ret_list.append(-1)
ret_list.append('Error')
ret_list.append('Error')
ret_list.append('Error')
return ret_list
------------
... which is called by...
m = get_class_by_title(classList, j)
Unfortunately, the same, it seems, cannot be said when I make the comparison
using something other than a string. For example...
# Define a function to retrieve a particular class association based on the
element number...
def get_class_association_by_element_number(objList, given_element_number):
found = 0
ret_list = []
# Run through the objects in the staff folder to see if there is a match
(with given_element_number)...
try:
for obj in objList:
if found == 0:
if given_element_number == obj.element_number:
ret_list.append(obj.absolute_url) # List element 0
ret_list.append(obj.title) # List element 1
ret_list.append(obj.element_number) # List element 2
ret_list.append(obj.instance_type) # List element 3
ret_list.append(obj.f_class) # List element 4
ret_list.append(obj.to_class) # List element 5
found = 1 # Set flag on success...
except:
ret_list.append('Blew out of try block.')
ret_list.append('Error')
ret_list.append(-1)
ret_list.append('Error')
ret_list.append('Error')
ret_list.append('Error')
found = 1
# Return indicative values if the desired object was not found...
if found == 0:
ret_list.append('Error')
ret_list.append('Error')
ret_list.append(-1)
ret_list.append('Error')
ret_list.append('Error')
ret_list.append('Error')
return ret_list
... consistently returns an error when called by...
n = get_class_association_by_element_number(classAssociationList,
string.atoi(j))
where j is a string element that is stored in a lines property of the object
in question.
When this code is executed, I get a TypeError: cannot add type "Python
Method" to string
Does anyone know what the problem is?
Note, I've done some diagnostics and simply had the method return the input
value (given_element_number) and it does so properly.
Here is the rest of the diagnostic information...
Traceback (innermost last):
File /usr/local/zope/2-4-3/lib/python/ZPublisher/Publish.py, line 223, in
publish_module
File /usr/local/zope/2-4-3/lib/python/ZPublisher/Publish.py, line 187, in
publish
File /usr/local/zope/2-4-3/lib/python/Zope/__init__.py, line 226, in
zpublisher_exception_hook
(Object: 066543_0103)
File /usr/local/zope/2-4-3/lib/python/ZPublisher/Publish.py, line 171, in
publish
File /usr/local/zope/2-4-3/lib/python/ZPublisher/mapply.py, line 160, in
mapply
(Object: get_text)
File /usr/local/zope/2-4-3/lib/python/ZPublisher/Publish.py, line 112, in
call_object
(Object: get_text)
File /usr/local/zope/2-4-3/lib/python/Shared/DC/Scripts/Bindings.py, line
324, in __call__
(Object: get_text)
File /usr/local/zope/2-4-3/lib/python/Shared/DC/Scripts/Bindings.py, line
354, in _bindAndExec
(Object: get_text)
File
/usr/local/zope/2-4-3/lib/python/Products/PythonScripts/PythonScript.py,
line 363, in _exec
(Object: get_text)
(Info: ({'script': <PythonScript instance at 8ae0a88>, 'context':
<Folder instance at 8cd9a20>, 'container': <Folder instance at 8b17d48>,
'namespace': <TemplateDict object at 0x87eb248>, 'traverse_subpath': []},
('0',), {}, None))
File Script (Python), line 264, in get_text
TypeError: (see above)
This is a really strange error. Can anyone give me a hint as to what the
problem is?
Thanks in advance,
Ron