Skip to content

Instantly share code, notes, and snippets.

@ZipFile
Created March 4, 2026 13:26
Show Gist options
  • Select an option

  • Save ZipFile/4239a57c12da6eaba5678088b3c36a71 to your computer and use it in GitHub Desktop.

Select an option

Save ZipFile/4239a57c12da6eaba5678088b3c36a71 to your computer and use it in GitHub Desktop.
Python's `print(repr(obj))`, but in C
#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