summaryrefslogtreecommitdiff
path: root/docs/examples/tutorial/string/assignment.pyx
diff options
context:
space:
mode:
Diffstat (limited to 'docs/examples/tutorial/string/assignment.pyx')
-rw-r--r--docs/examples/tutorial/string/assignment.pyx12
1 files changed, 12 insertions, 0 deletions
diff --git a/docs/examples/tutorial/string/assignment.pyx b/docs/examples/tutorial/string/assignment.pyx
new file mode 100644
index 000000000..aaf3fef4f
--- /dev/null
+++ b/docs/examples/tutorial/string/assignment.pyx
@@ -0,0 +1,12 @@
+from libc.stdlib cimport free
+from c_func cimport c_call_returning_a_c_string
+
+
+def main():
+ cdef char* c_string = c_call_returning_a_c_string()
+ cdef bytes py_string = c_string
+
+ # A type cast to `object` or `bytes` will do the same thing:
+ py_string = <bytes> c_string
+
+ free(c_string)