Re: [Pyobjc-dev] Calling function with variable number of arguments?
Brought to you by:
ronaldoussoren
From: Pierce T.W. I. <pi...@tw...> - 2004-04-27 20:04:55
|
On Apr 27, 2004, at 12:52 PM, Ronald Oussoren wrote: > > On 27-apr-04, at 21:19, Pierce T.Wetter III wrote: > >> >> So this line is giving me an error: >> >> qual= ObjectModel.EOQualifier.qualifierWithQualifierFormat_('fund = >> %@ and date >= %@',fund,now60) >> >> TypeError: Need 1 arguments, got 3 >> >> (1.1 b2 downloaded about 15 minutes ago) >> >> Presumably because qualifierWithQualifierFormat takes a variable >> number of arguments. >> >> Is there some sort of voodoo I can do to get this to work? > > The easiest solution is to do the formatting on the python side: > > qual= ObjectModel.EOQualifier.qualifierWithQualifierFormat_('fund = %s > and date >= %s'%(fund,now60)) > > It is possible to write C code that would allow you to pass in a > variable number of arguments, but you would have to implement most of > the format-string parsing in the wrapper. Yeah, that doesn't work, because it just looks like a format string, its actually parsed. For instance, an AND in the string produces an EOAndQualifier etc. What I did instead was add this in a category to EOQualifier: + (EOQualifier *) qualifierWithQualifierFormat: (NSString *) string arg1: (id) arg1 arg2:(id) arg2 { return [self qualifierWithQualifierFormat: string,arg1,arg2]; } Though that's a hack obviously. I wonder if it would be possible to do something like this: objc.makeVarArgsCall(ObjectModel.EOQualfier,"qualifierWithQualifierForma t_",('fund = %s and date >= %s',fund,now60)) That is, add a method to the objc module that takes an object, a selector and a list of arguments and makes the call? Pierce |