diff options
author | gabrieldemarmiesse <gabriel.demarmiesse@teraki.com> | 2018-06-16 19:08:11 +0200 |
---|---|---|
committer | gabrieldemarmiesse <gabriel.demarmiesse@teraki.com> | 2018-06-16 19:08:11 +0200 |
commit | 9cbd59ed0a01b622e3895b1909c27f43adf873e0 (patch) | |
tree | 59e10a6e575f30278076079865b05ab7ff623857 /docs/examples/tutorial/string/assignment.pyx | |
parent | 3d291a58b10e3f27a1933299b8787da69791e035 (diff) | |
download | cython-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.pyx | 12 |
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)
|