summaryrefslogtreecommitdiff
path: root/docs/examples/tutorial/string/assignment.pyx
diff options
context:
space:
mode:
authorgabrieldemarmiesse <gabriel.demarmiesse@teraki.com>2018-06-16 19:08:11 +0200
committergabrieldemarmiesse <gabriel.demarmiesse@teraki.com>2018-06-16 19:08:11 +0200
commit9cbd59ed0a01b622e3895b1909c27f43adf873e0 (patch)
tree59e10a6e575f30278076079865b05ab7ff623857 /docs/examples/tutorial/string/assignment.pyx
parent3d291a58b10e3f27a1933299b8787da69791e035 (diff)
downloadcython-9cbd59ed0a01b622e3895b1909c27f43adf873e0.tar.gz
Extended the examples of string.rst and put them in the examples directory for testing.
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)