Skip to content

Commit dfdf8f2

Browse files
knuth-bendix: fix helper to_latin1
1 parent 9d437b4 commit dfdf8f2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/knuth-bendix.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ namespace libsemigroups {
5353

5454
namespace {
5555
std::string to_latin1(std::string const& u) {
56-
static py::object bytes = py::globals()["__builtins__"]["bytes"];
56+
static py::object bytes;
57+
try {
58+
bytes = py::getattr(py::globals()["__builtins__"], "bytes");
59+
} catch (py::error_already_set& e) {
60+
bytes = py::globals()["__builtins__"]["bytes"];
61+
}
5762
return PyBytes_AS_STRING(bytes(py::str(u), "latin1").ptr());
5863
}
5964

0 commit comments

Comments
 (0)