Nerodia Reference Manual

8.9. PyStr🔗

🔗def

A Python unicode object. That is, an instance of str.

🔗def

The Python string type, str.

🔗opaque
Nerodia.mkPyStr (s : String) : CPyIO PyStr
Nerodia.mkPyStr (s : String) : CPyIO PyStr

Creates a Python string from a Lean string.

🔗opaque
Nerodia.PyStr.toString (self : PyStr) : String
Nerodia.PyStr.toString (self : PyStr) : String

Returns the UTF8-encoded value of self as a Lean String.

If the string contains lone surrogates (and is thus not valid UTF-8), they will be replaced with � (U+FFFD, the official Unicode replacement character), following Lean's standard lossy encoding.

8.9.1. Encoding to bytes🔗

🔗opaque
Nerodia.PyStr.encode (self : PyStr) (encoding : CodecEncoding) (errors : CodecErrors := CodecErrors.strict) : CPyIO PyBytes
Nerodia.PyStr.encode (self : PyStr) (encoding : CodecEncoding) (errors : CodecErrors := CodecErrors.strict) : CPyIO PyBytes

Returns the string encoded as bytes.

This is equivalent to the Python str.encode(self, encoding, errors).

🔗def

Returns the UTF-8-encoded value of the string as bytes.

This is equivalent to self.encode .utf8 .strict but more efficient.