471,342 Members | 1,632 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,342 software developers and data experts.

Cost of "unicode(s)" where s is Unicode

Does

text = unicode(text)

make a copy of a Unicode string, or is that essentially a
free operation if the input is already Unicode?

John Nagle
Jan 6 '08 #1
5 1159
John Nagle wrote in news:47***********************@news.sonic.net in
comp.lang.python:
Does

text = unicode(text)

make a copy of a Unicode string, or is that essentially a
free operation if the input is already Unicode?

John Nagle
http://docs.python.org/lib/built-in-funcs.html#l2h-78

... More precisely, if object is a Unicode string or subclass it
will return that Unicode string without any additional decoding
applied.
...
Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jan 6 '08 #2
John Nagle wrote:
Does

text = unicode(text)

make a copy of a Unicode string, or is that essentially a
free operation if the input is already Unicode?
>>u = u"some long unicode object"
unicode(u) is u
True
Jan 6 '08 #3
John Nagle wrote:
Does

text = unicode(text)

make a copy of a Unicode string, or is that essentially a
free operation if the input is already Unicode?
>>u = u"some long unicode object"
unicode(u) is u
True

Jan 6 '08 #4
On Jan 6, 9:06 am, John Nagle <na...@animats.comwrote:
Does

text = unicode(text)

make a copy of a Unicode string, or is that essentially a
free operation if the input is already Unicode?

John Nagle
>>u = u"abc"
uu = unicode(u)
u is uu
True
>>s = "abc"
ss = unicode(s)
s is ss
False

HTH,
Jon Peck
Jan 6 '08 #5
In article <70**********************************@d70g2000hsb. googlegroups.com>,
JKPeck <JK****@gmail.comwrote:
>
>>>u = u"abc"
uu = unicode(u)
u is uu
True
>>>s = "abc"
ss = unicode(s)
s is ss
False
You uuencode Unicode?
--
Aahz (aa**@pythoncraft.com) <* http://www.pythoncraft.com/

Sorry, couldn't resist the alliteration
Jan 6 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Petr Prikryl | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.