content = "MASBicudo" bytes_utf8 = content.encode("utf-8") with open("filename.txt", "wb") as fs: fs.write(bytes_utf8)
str has the encode method, that returns bytes with the encoded string.
str
encode
bytes