Closed
Description
Issue description
Example from documentation isn't working
http://pybind11.readthedocs.io/en/master/advanced/embedding.html#getting-started
py::exec(R"(
kwargs = dict(name="World", number=42)
message = "Hello, {name}! The answer is {number}".format(**kwargs)
print(message)
)");
Error:
terminate called after throwing an instance of 'pybind11::error_already_set'
what(): NameError: name 'dict' is not defined
At:
<string>(3): <module>
This also isn't working:
py::exec(R"(
#kwargs = {'name':"World", 'number':42}
#message = "Hello, {name}! The answer is {number}".format(**kwargs)
print("Hello")
)");
Error:
terminate called after throwing an instance of 'pybind11::error_already_set'
what(): NameError: name 'print' is not defined
At:
<string>(5): <module>
Reproducible example code
#include <iostream>
#include <pybind11/embed.h> // everything needed for embedding
namespace py = pybind11;
int main()
{
py::scoped_interpreter guard{}; // start the interpreter and keep it alive
py::exec(R"(
kwargs = dict(name="World", number=42)
message = "Hello, {name}! The answer is {number}".format(**kwargs)
print(message)
)");
py::exec(R"(
#kwargs = {'name':"World", 'number':42}
#message = "Hello, {name}! The answer is {number}".format(**kwargs)
print("Hello")
)");
return 0;
}
Metadata
Metadata
Assignees
Labels
No labels