Comments (4)
Ha! I definitely need to learn python. thank you a lot!
from pybind11_json.
Do you mind showing the code of the class? I don't see what's wrong with this code.
from pybind11_json.
class myClass
{
public:
void take_json(const nlohmann::json& json) {
std::cout << "This function took an nlohmann::json instance as argument: " << json.dump() << std::endl;
}
};
PYBIND11_MODULE(myModule, module)
{
py::class_<myClass>(module, "myClass") // for inheritance, we must include the base class
.def(py::init<>())
.def("take_json", &myClass::take_json, "pass py::object to a C++ function that takes an nlohmann::json");
}
on python:
a=myModule.myClass
a.take_json({"a": 1})
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-5-97ad54179472> in <module>
1 a=myModule.myClass
----> 2 a.take_json({"a": 1})
TypeError: take_json(): incompatible function arguments. The following argument types are supported:
1. (self: myModule.myClass, arg0: json) -> None
Invoked with: {'a': 1}
from pybind11_json.
Looks like you forgot the parenthesis at the end of the first line of python
from pybind11_json.
Related Issues (20)
- C++ returning nlohmann::json to Python. Is it possible? HOT 2
- Error: nlohmann::json as input argument HOT 2
- Bind nlohmann::json::array_t is possible? HOT 10
- How can I debug? HOT 3
- Allow automatic cast from nlohmann::json to py::object in return type of functions HOT 7
- bytes, bytearray, memoryview support
- set, frozenset support HOT 1
- Build fails with CMake version < 3.14
- Infinity mishandled in nl::json => py::object conversion
- Cannot include dependencies with add_directories
- Support for binary arrays HOT 3
- local variable 'obj' will be copied despite being returned by name HOT 1
- What about enumerations?
- No 'test' target when BUILD_TESTS=ON
- [question] Python + C++ full example?
- support for `nlohmann::ordered_json` in addition to `nlohmann::json` HOT 2
- CMake deprecation warning HOT 3
- Redundant Move in from_json
- support for other kind of python object or class HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pybind11_json.