Differences between revisions 1 and 2
Revision 1 as of 2002-09-25 19:57:58
Size: 711
Editor: MikeRovner
Comment:
Revision 2 as of 2007-04-19 21:26:03
Size: 717
Editor: c-71-197-167-221
Comment: Corrected explicit check code
Deletions are marked like this. Additions are marked like this.
Line 20: Line 20:
        extractor<int> get_int(x);
        if (get_int)
        extract<int> get_int(x);
        if (get_int.check())

extractor interface which can be used to extract C++ types from Python objects.

We have discussed two main use cases for extractions

1. In user code which needs to retrieve C++ objects from their corresponding Python objects:

  1. Getting value:
    •     void f(object x)
          {
              int y = extract<int>(x); // retrieve an int from x
          }
  2. Users may also want to explicitly check for convertibility:
    •     int g(object x)
          {
              extract<int> get_int(x);
              if (get_int.check())
                  return get_int();
              else
                  return 0;
          }

2. In the implementation of sequence from_python converters (e.g. Python tuple/list -> std::vector)

boost.python/extract (last edited 2012-02-28 15:53:49 by 195)

Unable to edit the page? See the FrontPage for instructions.