ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 07 Aug 2015 09:24:42 +0200character encodinghttps://ask.sagemath.org/question/26556/character-encoding/ How can I chgange characte encoding in Sage notebook. I'm hungarian, and in string I need characterd like á, ő, ű, etc, but not \xc3, \xc5 and so on.Thu, 16 Apr 2015 10:57:45 +0200https://ask.sagemath.org/question/26556/character-encoding/Comment by kcrisman for <p>How can I chgange characte encoding in Sage notebook. I'm hungarian, and in string I need characterd like á, ő, ű, etc, but not \xc3, \xc5 and so on.</p>
https://ask.sagemath.org/question/26556/character-encoding/?comment=26674#post-id-26674And see also https://groups.google.com/forum/#!topic/sage-support/QmXvzgNONNYTue, 28 Apr 2015 20:29:22 +0200https://ask.sagemath.org/question/26556/character-encoding/?comment=26674#post-id-26674Comment by kcrisman for <p>How can I chgange characte encoding in Sage notebook. I'm hungarian, and in string I need characterd like á, ő, ű, etc, but not \xc3, \xc5 and so on.</p>
https://ask.sagemath.org/question/26556/character-encoding/?comment=26567#post-id-26567See also the presumably identical http://ask.sagemath.org/question/8249/unicode-in-doc-strings/Thu, 16 Apr 2015 16:48:15 +0200https://ask.sagemath.org/question/26556/character-encoding/?comment=26567#post-id-26567Answer by yanmercal for <p>How can I chgange characte encoding in Sage notebook. I'm hungarian, and in string I need characterd like á, ő, ű, etc, but not \xc3, \xc5 and so on.</p>
https://ask.sagemath.org/question/26556/character-encoding/?answer=28767#post-id-28767 A character encoding tells the computer how to interpret raw zeroes and ones into real characters. It usually does this by pairing numbers with characters. Words and sentences in text are created from characters and these characters are grouped into a character set. There are many different types of character encodings floating around at present, but the ones we deal most frequently with are ASCII, 8-bit encodings, and Unicode-based encodings. More about.....[Character Encoding](http://net-informations.com/q/faq/encoding.html)
MercalFri, 07 Aug 2015 09:24:42 +0200https://ask.sagemath.org/question/26556/character-encoding/?answer=28767#post-id-28767Answer by kcrisman for <p>How can I chgange characte encoding in Sage notebook. I'm hungarian, and in string I need characterd like á, ő, ű, etc, but not \xc3, \xc5 and so on.</p>
https://ask.sagemath.org/question/26556/character-encoding/?answer=26569#post-id-26569Apparently for now you may have to use the `print` command.
print u"gömböc"
works, indeed even without the `u`. See e.g. http://stackoverflow.com/questions/10569438/how-to-print-unicode-character-in-pythonThu, 16 Apr 2015 16:53:19 +0200https://ask.sagemath.org/question/26556/character-encoding/?answer=26569#post-id-26569Comment by slelievre for <p>Apparently for now you may have to use the <code>print</code> command.</p>
<pre><code>print u"gömböc"
</code></pre>
<p>works, indeed even without the <code>u</code>. See e.g. <a href="http://stackoverflow.com/questions/10569438/how-to-print-unicode-character-in-python">http://stackoverflow.com/questions/10...</a></p>
https://ask.sagemath.org/question/26556/character-encoding/?comment=26571#post-id-26571You are right, `print` is the key to printing a string properly. Prefixing `u` to the string changes how it is encoded, which might matter for the subsequent use of the string.Thu, 16 Apr 2015 19:08:42 +0200https://ask.sagemath.org/question/26556/character-encoding/?comment=26571#post-id-26571Answer by slelievre for <p>How can I chgange characte encoding in Sage notebook. I'm hungarian, and in string I need characterd like á, ő, ű, etc, but not \xc3, \xc5 and so on.</p>
https://ask.sagemath.org/question/26556/character-encoding/?answer=26559#post-id-26559EDITED. My original answer
> You can prefix a string with the letter `u` to mark it as a unicode string, eg `u'gömböc'`.
was not so helpful. The notes below are maybe more a related discussion than a proper answer.
You can prefix a string with the letter `u` to mark it as a unicode string.
If you are inputting unicode characters, this will affect how the string is encoded.
Here is what I get in the Sage REPL.
sage: 'Erdős'
'Erd\xc5\x91s'
sage: u'Erdős'
u'Erd\u0151s'
This shows a difference in the escape codes used for accented characters.
Apparently @kcrisman's indication to use `print` is the key to properly displaying unicode strings.
sage: print 'Erdős'
Erdős
sage: print u'Erdős'
Erdős
The role of the `u` prefix is not so apparent here.
The `u` is useful if you are using unicode escape codes in the string.
sage: print 'Erd\u0151s'
Erd\u0151s
sage: print u'Erd\u0151s'
Erdős
The other version:
sage: print 'Erd\xc5\x91s'
Erdős
Thu, 16 Apr 2015 12:14:31 +0200https://ask.sagemath.org/question/26556/character-encoding/?answer=26559#post-id-26559Comment by czsan for <p>EDITED. My original answer</p>
<blockquote>
<p>You can prefix a string with the letter <code>u</code> to mark it as a unicode string, eg <code>u'gömböc'</code>.</p>
</blockquote>
<p>was not so helpful. The notes below are maybe more a related discussion than a proper answer.</p>
<p>You can prefix a string with the letter <code>u</code> to mark it as a unicode string.
If you are inputting unicode characters, this will affect how the string is encoded.</p>
<p>Here is what I get in the Sage REPL.</p>
<pre><code>sage: 'Erdős'
'Erd\xc5\x91s'
sage: u'Erdős'
u'Erd\u0151s'
</code></pre>
<p>This shows a difference in the escape codes used for accented characters.</p>
<p>Apparently <a href="/users/41/kcrisman/">@kcrisman</a>'s indication to use <code>print</code> is the key to properly displaying unicode strings.</p>
<pre><code>sage: print 'Erdős'
Erdős
sage: print u'Erdős'
Erdős
</code></pre>
<p>The role of the <code>u</code> prefix is not so apparent here.</p>
<p>The <code>u</code> is useful if you are using unicode escape codes in the string.</p>
<pre><code>sage: print 'Erd\u0151s'
Erd\u0151s
sage: print u'Erd\u0151s'
Erdős
</code></pre>
<p>The other version:</p>
<pre><code>sage: print 'Erd\xc5\x91s'
Erdős
</code></pre>
https://ask.sagemath.org/question/26556/character-encoding/?comment=26561#post-id-26561The respone is u'g\xf6mb\xf6c'Thu, 16 Apr 2015 12:26:16 +0200https://ask.sagemath.org/question/26556/character-encoding/?comment=26561#post-id-26561