diff --git a/python/obitools3/utils.pxd b/python/obitools3/utils.pxd index 0eafa4d..2a1b144 100644 --- a/python/obitools3/utils.pxd +++ b/python/obitools3/utils.pxd @@ -1,5 +1,6 @@ #cython: language_level=3 + cdef bytes str2bytes(str string) cdef str bytes2str(bytes string) \ No newline at end of file diff --git a/python/obitools3/utils.pyx b/python/obitools3/utils.pyx index 183b373..793e7f1 100644 --- a/python/obitools3/utils.pyx +++ b/python/obitools3/utils.pyx @@ -1,7 +1,28 @@ #cython: language_level=3 +import sys +import io + cdef bytes str2bytes(str string): + """ + Short cut to convert ascii encoded python string (str) to bytes + which can be easily converted to C-strings. + + @param string: the python string to be converted. + @type string: str + @return a transcoded string + @rtype: bytes + """ return string.encode('ascii') cdef str bytes2str(bytes string): - return string.decode('ascii') \ No newline at end of file + """ + Short cut to convert bytes (C-strings) to ascii encoded python string (str). + + @param string: the binary (C-string) string to be converted. + @type string: bytes + @return an ascii transcoded string + @rtype: str + """ + return string.decode('ascii') +