A few problems with apply()
Ben Leslie
benno at sesgroup.net
Sat May 18 07:49:58 EDT 2002
I am having a couple of problems using apply.
I have an object which "looks" like a dictionary
with unicode strings as keys. (By looks like I mean
the object implement the mapping protocol, specifically
it is the AttributesImpl object in the xml library.)
This firstly fails with:
TypeError: apply() arg 3 expected dictionary, found instance
Obviously apply needs a real dictionary. Firstly, is this the
correct behaviour? Is there any good reason apply shouldn't
handle this?
This can trivially be got around with a simple loop to copy
the data from the object into a real dictionary.
After doing this I then got the following error:
TypeError: __init__() keywords must be strings
This is obviously because these are unicode strings, not
ascii strings. This can obviously be fixed with:
k.encode('ascii').
My question again is there a good reason the apply() function
can't handler unicode strings. (Actually I think the problem
is further down in PyEval_EvalCodeEx in ceval.c)
Thanks in advance,
Benno
More information about the Python-list
mailing list