Function: text.encode

Encodes given text to bytes, using the specified character set.

Arguments

Arguments
text

string

The input to be encoded.

charset

string

The IANA charset name; e.g. UTF-8, US-ASCII, ISO-8859-2. Case-insensitive. Default: UTF-8.

Returns

The encoded bytes.

Raised exceptions

Exceptions
ValueError If the charset is unsupported, or if the text contains codepoints that are not representable in the specified charset.