Arbitrary argument lists, Python style?
Forgive me if I'm just being dense, but in hours of searching multiple archives, I have not been able to find a way to implement the following Python code in C++ via BPL (simplified somewhat for purposes of this discussion): class BackCaller: def SetCallback(self, action, *args): self.cb = (action, args) def CallItBack(self): if self.cb: (action, args) = self.cb return action(*args) The thing that's causing me to pull foot-long hairs from my head is that little *args Is such a thing possible, or do I need to do one of the following: 1) Tell my Python users that they have to explicitly wrap their args in a tuple? 2) Write a Python wrapper that does the translation back and forth between the variable arg list and a tuple that can be passed explicitly to and from my BPL-wrapped class? (and no, I'm not just doing this for fun - I've got some existing Python code that is being redone in C++ because it needs to live closer to the wire) -Conan This message contains information that may be confidential and privileged. Unless you are the addressee (or authorized to receive messages for the addressee), you may not use, copy, or disclose to anyone the message or any information contained in the message. If you have received the message in error, please advise the sender by reply e-mail and delete the message. Nothing in this message should be interpreted as a digital or electronic signature that can be used to authenticate a contract or any other legal document.
"Conan Brink" <conanb@STCG.net> writes:
Forgive me if I'm just being dense, but in hours of searching multiple archives, I have not been able to find a way to implement the following Python code in C++ via BPL (simplified somewhat for purposes of this discussion):
class BackCaller:
def SetCallback(self, action, *args):
self.cb = (action, args)
def CallItBack(self):
if self.cb:
(action, args) = self.cb
return action(*args)
The thing that's causing me to pull foot-long hairs from my head is that little *args
Does http://tinyurl.com/ibc6 help? -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (2)
-
Conan Brink -
David Abrahams