Bytes-like object when using a python module
Hi there, I'm checking out mojo and was going to make a little IRC client using the basic python
socket
module, but I ran into an issue when trying to call socket.send
which was: a bytes-like object is required, not 'str'
.
So I tried to get the underlying buffer from the string and got a compile error: argument #1 cannot be converted from 'DynamicVector[SIMD[si8, 1]]' to 'PythonObject'
I'm new to mojo and my python is very rusty, but I couldn't find a way to get a bytes-like python object, is there a stdlib function somewhere that I'm missing?6 Replies
I think what you are looking for is the Python method on
str
: "string".encode("utf-8")
.How do I use that method on a mojo
String
? Since it's a built in python type I'm not sure how to import/use itOh it's an actual module called builtins 🤦♀️
This did work! Thanks for sharing your brainpower with me 🙂
It's actually the Python module
builtins
.Yeah, I was looking in the python docs but I was on a page talking about the
builtins
stuff but since it was talking about things that are automatically imported to python I didn't realize that it's in a literal module called builtins