Created
March 4, 2026 13:26
-
-
Save ZipFile/4239a57c12da6eaba5678088b3c36a71 to your computer and use it in GitHub Desktop.
Python's `print(repr(obj))`, but in C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <Python.h> | |
| static void reprint(PyObject *obj) { | |
| PyObject* repr = PyObject_Repr(obj); | |
| PyObject* str = PyUnicode_AsEncodedString(repr, "utf-8", "~E~"); | |
| const char *bytes = PyBytes_AsString(str); | |
| printf("REPR: %s\n", bytes); | |
| Py_XDECREF(repr); | |
| Py_XDECREF(str); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment