-
I have a String and I would like to convert it into a byte array (so presumably a |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 15 replies
-
maybe this from Vector import DynamicVector
from String import String
let vec : DynamicVector[SI8] = String("hello world").buffer |
Beta Was this translation helpful? Give feedback.
-
and how to print the vec variable, we need builtins module? from Vector import DynamicVector
from String import String
from PythonInterface import Python
let vec : DynamicVector[SI8] = String("hello world").buffer
let builtins = Python.import_module("builtins")
builtins.print(vec) error: Expression [4]:23:19: invalid call to 'call': argument #1 cannot be converted from 'DynamicVector[SIMD[si8, 1]]' to 'PythonObject' /.modular/Kernels/mojo/Python/PythonObject.mojo:210:5: function declared here |
Beta Was this translation helpful? Give feedback.
-
from Vector import DynamicVector
from String import String
fn conversion_to_utf(my_string) -> str:
let vec : DynamicVector[SI8] = String(my_string).buffer
return vec
conversion_to_utf("hello world") _error: Expression [13]:8:36: use of unknown declaration 'str', 'fn' declarations require explicit variable declarations error: Expression [13]:8:22: 'fn' parameter type must be specified |
Beta Was this translation helpful? Give feedback.
-
hey @czheo, how do opposite, convert DynamicVector[SI8] into String? |
Beta Was this translation helpful? Give feedback.
-
Closing this out given there is a clear answer above |
Beta Was this translation helpful? Give feedback.
-
Can you please share how you wrote SI8? |
Beta Was this translation helpful? Give feedback.
maybe this