Sending string var with apply sends all chars as params!???

GimsMail elabuschagne at gims.com
Tue Jun 25 11:03:58 EDT 2002


Hi all,

I am having problems with the apply function in Python.  When applying a string variable to a method, the string var gets chopped up into all it chars and each char gets sent as a parameter!  The result is getting a TypeError because I am sending too much parameters to the function (more detail below if you still don't understand)

Regards
Etienne

Detailed explanation:
When running my program I get the following:

My print line debugging string output:
Formatting value '20020625140609' of type <type 'string' with formatter <function TimeFormatter at 00D613F4>

as you can see, I am sending the string '20020625140609' to the function TimeFormatter.

The code that does this is:
print "UCP: Formatting value '%s' of type '%s' with formatter '%s'" %(value, type(value), formatter)
value = apply(formatter,(str(value)))

in this case, formatter is the function TimeFormatter (as defined in a mapping table)

When this code executes I get a TypeError:

TypeError: TimeFormatter() takes exactly 1 argument (14 given).

Why is the string (which is 14 chars long) broken up into 14 values when passed using apply!?

The weird thing is this code has been working for MONTHS and have only recently stopped working after some refactoring in a completely different part of code!

The problem goes away when I don't use apply:
value = formatter(value)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20020625/3443d575/attachment.html>


More information about the Python-list mailing list