[python] extracting a string and a one-length list containing a string

Hello, Given a boost::python object, how can I the difference between that object containing a string, or a sequence of length 1 whos zeroeth element is a string? Ie: "foo" --vs-- ["foo"] bp::extract<std::string> succeeds in both cases. I can use PySequence_Check to test for a sequence, and then I can test the length of the zeroeth element - if >1 then it's ["foo"] - but then I still can't disambiguate ["X"]. tia! Allan

At Thu, 10 Mar 2011 09:33:27 +1100, Allan Johns wrote:
Hello,
Given a boost::python object, how can I the difference between that object containing a string, or a sequence of length 1 whos zeroeth element is a string? Ie:
"foo" --vs-- ["foo"]
bp::extract<std::string> succeeds in both cases.
I'm shocked. Really? Can you show the code? -- Dave Abrahams BoostPro Computing http://www.boostpro.com

Ok the problem is nothing to do with boost python, but some lack of python knowledge on my behalf. I didn't know about the quirky syntax for construction of 1-length tuples, and was wondering why this argument was being extracted as a string and not a 1-length tuple:
foo( ("str") )
Of course, it was a string all along. thx A On Sat, Mar 12, 2011 at 10:35 PM, Dave Abrahams <dave@boostpro.com> wrote:
At Thu, 10 Mar 2011 09:33:27 +1100, Allan Johns wrote:
Hello,
Given a boost::python object, how can I the difference between that
object
containing a string, or a sequence of length 1 whos zeroeth element is a string? Ie:
"foo" --vs-- ["foo"]
bp::extract<std::string> succeeds in both cases.
I'm shocked. Really? Can you show the code?
-- Dave Abrahams BoostPro Computing http://www.boostpro.com
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (2)
-
Allan Johns
-
Dave Abrahams