how to find out utf or not

Neil Cerutti neilc at norwich.edu
Tue Nov 5 10:30:19 EST 2013


On 2013-11-05, Dave Angel <davea at davea.name> wrote:
> On Tue, 05 Nov 2013 16:32:57 +0330, Mohsen Pahlevanzadeh 
><mohsen at pahlevanzadeh.org> wrote:
>> Suppose i have a variable such as : myVar = 'x'
>
>> May be it initialized with myVar = u'x' or myVar = 'x'
>
>> So i need determine content of myVar that it's utf-8 or not, how 
> can i
>> do it?
>
> Use the type() function and compare to unicode or str
> respectively. E.g.  If type(myvar)==unicode:

That will tell you wether it's a unicode string or a byte string,
but not the encoding of the source bytes. Unless there's some
context I'm not privy to.

u'x' is (hopefully) decoded already, but the encoding of 'x' is
unknown.

-- 
Neil Cerutti



More information about the Python-list mailing list