mirror of
https://github.com/pybind/pybind11.git
synced 2026-06-07 08:15:22 +00:00
refactor: module -> module_ with typedef (#2544)
* WIP: module -> module_ without typedef * refactor: allow py::module to work again
This commit is contained in:
@@ -56,12 +56,12 @@ This example obtains a reference to the Python ``Decimal`` class.
|
||||
.. code-block:: cpp
|
||||
|
||||
// Equivalent to "from decimal import Decimal"
|
||||
py::object Decimal = py::module::import("decimal").attr("Decimal");
|
||||
py::object Decimal = py::module_::import("decimal").attr("Decimal");
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
// Try to import scipy
|
||||
py::object scipy = py::module::import("scipy");
|
||||
py::object scipy = py::module_::import("scipy");
|
||||
return scipy.attr("__version__");
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ via ``operator()``.
|
||||
.. code-block:: cpp
|
||||
|
||||
// Use Python to make our directories
|
||||
py::object os = py::module::import("os");
|
||||
py::object os = py::module_::import("os");
|
||||
py::object makedirs = os.attr("makedirs");
|
||||
makedirs("/tmp/path/to/somewhere");
|
||||
|
||||
@@ -196,9 +196,9 @@ C++ functions that require a specific subtype rather than a generic :class:`obje
|
||||
#include <pybind11/numpy.h>
|
||||
using namespace pybind11::literals;
|
||||
|
||||
py::module os = py::module::import("os");
|
||||
py::module path = py::module::import("os.path"); // like 'import os.path as path'
|
||||
py::module np = py::module::import("numpy"); // like 'import numpy as np'
|
||||
py::module_ os = py::module_::import("os");
|
||||
py::module_ path = py::module_::import("os.path"); // like 'import os.path as path'
|
||||
py::module_ np = py::module_::import("numpy"); // like 'import numpy as np'
|
||||
|
||||
py::str curdir_abs = path.attr("abspath")(path.attr("curdir"));
|
||||
py::print(py::str("Current directory: ") + curdir_abs);
|
||||
|
||||
@@ -42,7 +42,7 @@ redirects output to the corresponding Python streams:
|
||||
m.def("noisy_func", []() {
|
||||
py::scoped_ostream_redirect stream(
|
||||
std::cout, // std::ostream&
|
||||
py::module::import("sys").attr("stdout") // Python output
|
||||
py::module_::import("sys").attr("stdout") // Python output
|
||||
);
|
||||
call_noisy_func();
|
||||
});
|
||||
@@ -104,7 +104,7 @@ can be used.
|
||||
...
|
||||
|
||||
// Evaluate in scope of main module
|
||||
py::object scope = py::module::import("__main__").attr("__dict__");
|
||||
py::object scope = py::module_::import("__main__").attr("__dict__");
|
||||
|
||||
// Evaluate an isolated expression
|
||||
int result = py::eval("my_variable + 10", scope).cast<int>();
|
||||
|
||||
Reference in New Issue
Block a user