Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #58504 > unrolled thread

Re: how to find out utf or not

Started byDave Angel <davea@davea.name>
First post2013-11-05 08:41 -0600
Last post2013-11-06 00:03 -0600
Articles 3 — 2 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: how to find out utf or not Dave Angel <davea@davea.name> - 2013-11-05 08:41 -0600
    Re: how to find out utf or not Neil Cerutti <neilc@norwich.edu> - 2013-11-05 15:30 +0000
      Re: how to find out utf or not Dave Angel <davea@davea.name> - 2013-11-06 00:03 -0600

#58504 — Re: how to find out utf or not

FromDave Angel <davea@davea.name>
Date2013-11-05 08:41 -0600
SubjectRe: how to find out utf or not
Message-ID<mailman.2055.1383662485.18130.python-list@python.org>
On Tue, 05 Nov 2013 16:32:57 +0330, Mohsen Pahlevanzadeh 
<mohsen@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:

-- 
DaveA

[toc] | [next] | [standalone]


#58505

FromNeil Cerutti <neilc@norwich.edu>
Date2013-11-05 15:30 +0000
Message-ID<bdsh8bFcov1U1@mid.individual.net>
In reply to#58504
On 2013-11-05, Dave Angel <davea@davea.name> wrote:
> On Tue, 05 Nov 2013 16:32:57 +0330, Mohsen Pahlevanzadeh 
><mohsen@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

[toc] | [prev] | [next] | [standalone]


#58550

FromDave Angel <davea@davea.name>
Date2013-11-06 00:03 -0600
Message-ID<mailman.2075.1383717788.18130.python-list@python.org>
In reply to#58505
On 5 Nov 2013 15:30:19 GMT, Neil Cerutti <neilc@norwich.edu> wrote:
> On 2013-11-05, Dave Angel <davea@davea.name> wrote:
> > On Tue, 05 Nov 2013 16:32:57 +0330, Mohsen Pahlevanzadeh 
> >> May be it initialized with myVar = u'x' or myVar = 'x'

My solution assumed he wanted to distinguish between those two cases.


> >> So i need determine content of myVar that it's utf-8 or not, how 

I failed to notice thetypo in that line or the misunderstanding it 
implies.

-- 
DaveA

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web