Skip to content

Unable to store std::string in py::dict #547

@steve-lorimer

Description

@steve-lorimer

The below sample application fails to compile

#include <pybind11/pybind11.h>

namespace py = pybind11;

int main()
{
	py::dict dict;
	std::string value = "bar";
	dict["foo"] = value;

	return 0;
}

The error returned is:

main.cpp:40:14: error: no match for ‘operator=’ (operand types are \
    ‘pybind11::detail::item_accessor \
        {aka pybind11::detail::accessor<pybind11::detail::accessor_policies::generic_item>}’ \
    and ‘std::__cxx11::string \
        {aka std::__cxx11::basic_string<char>}’)
  dict["foo"] = value;

How does one store a string in a dict?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions