Validate string as UTF-8?

Fredrik Lundh fredrik at pythonware.com
Sun Nov 6 14:59:08 EST 2005


Tony Nelson wrote:

> I'd like to have a fast way to validate large amounts of string data as
> being UTF-8.

define "validate".

> I don't see a fast way to do it in Python, though:
>
>     unicode(s,'utf-8').encode('utf-8)

if "validate" means "make sure the byte stream doesn't use invalid
sequences", a plain

    unicode(s, "utf-8")

should be sufficient.

</F>






More information about the Python-list mailing list