472,090 Members | 1,319 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Help for unicode

Hello,

I'm italian and i not speak a good english. My problem is this:

Why this istruction:

print u"\u00" + str(41)

generate an error and this:

print u"\u0041" no?
Can I use all 65536 symbols of unicode in my program? For example, I need to
use the mathematic symbol of void set. It has a 0198 number in a table of
symbol that there is in Windows.

Thanks
--
Noixe
Jul 18 '05 #1
10 2660
Noixe wrote:
Why this istruction:

print u"\u00" + str(41)

generate an error and this:

print u"\u0041" no?
because they are doing very different things.
The first is first evaluating u"\u00" and only
if that succeeds (but it doesn't) add the string
"41" at the end.

The second is evaluating the unicode escape
sequence \u0041 that is part of the string.

You cannot combine strings like that to form
arbitrary unicode escape sequences. Try this instead;

some_variable=0x0041

print unichr(some_variable)

Can I use all 65536 symbols of unicode in my program? For example, I need to
use the mathematic symbol of void set. It has a 0198 number in a table of
symbol that there is in Windows.


No problem to use all unicode symbols.

But I don't think the empty set symbols is Unicode code point U+0198:
import unicodedata
unicodedata.name(u'\u0198') 'LATIN CAPITAL LETTER K WITH HOOK' unicodedata.lookup("EMPTY SET")

u'\u2205'

So I think you should use U+2205 instead?
--Irmen

Jul 18 '05 #2
Thanks!
Jul 18 '05 #3
"Irmen de Jong" <irmen@-NOSPAM-REMOVETHIS-xs4all.nl> ha scritto:

If I write:

print u'\u2205'

I have this error: UnicodeError: ASCII encoding error: ordinal not in
range(128)
Why? I must include some module?

--
Noixe
Jul 18 '05 #4
Noixe wrote:
Hello,

I'm italian and i not speak a good english. My problem is this:

Why this istruction:

print u"\u00" + str(41)

generate an error and this:

print u"\u0041" no?
That's because Unicode literals (\uxxxx) are interpreted at compile
time, not at runtime.
Can I use all 65536 symbols of unicode in my program? For example, I need to
use the mathematic symbol of void set. It has a 0198 number in a table of
symbol that there is in Windows.


I don't know which symbol this is in Unicode, maybe somebody else can?

-- Gerhard
Jul 18 '05 #5
"Noixe" <No**********@hotmail.com> writes:
print u'\u2205'

I have this error: UnicodeError: ASCII encoding error: ordinal not in
range(128)
Why? I must include some module?


No. Just don't print it:
x=u'\u2205'
x

u'\u2205'

The character U+2205 is EMPTY SET; your terminal is not capable of
displaying that symbol.

Regards,
Martin

Jul 18 '05 #6
"Martin v. Löwis" <ma****@v.loewis.de> ha scritto:
The character U+2205 is EMPTY SET; your terminal is not capable of
displaying that symbol.


Ah... and not exist one solution?

--
Noixe
Jul 18 '05 #7
Noixe wrote:
The character U+2205 is EMPTY SET; your terminal is not capable of
displaying that symbol.

Ah... and not exist one solution?


Change your output to something that *does* support displaying
U+2205, such as a HTML document that you then read with a
decent web browser.

Or you could use 'LATIN SMALL LETTER O WITH STROKE' instead,
U+00f8 (u'\xf8'). It looks very similar to the EMPTY SET symbol,
and because it is just a normal letter instead of a mathematical
symbol, it is much more likely to be supported by your terminal.

--Irmen

Jul 18 '05 #8
Noixe wrote:
The character U+2205 is EMPTY SET; your terminal is not capable of
displaying that symbol.

Ah... and not exist one solution?


What kind of output would you like to get? I'm sure it can be arranged,
if your computer hardware is good enough. However, you have to tell us
what solution you want.

Regards,
Martin

Jul 18 '05 #9
"Martin v. Löwis" <ma****@v.loewis.de> ha scritto:

No problem. It's no so important.

--
Noixe
Jul 18 '05 #10
In article <2p**********************@twister1.libero.it>,
"Noixe" <No**********@hotmail.com> wrote:
If I write:

print u'\u2205'

I have this error: UnicodeError: ASCII encoding error: ordinal not in
range(128)
Why? I must include some module?


You have to specify which encoding you want to print it in.
E.g.
print u'\u2205'.encode('utf8')


Of course this will only work if the output stream you print to is set
up to use that encoding...

--
David Eppstein http://www.ics.uci.edu/~eppstein/
Univ. of California, Irvine, School of Information & Computer Science
Jul 18 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Bernd Preusing | last post: by
reply views Thread by Chris | last post: by
1 post views Thread by Rahul | last post: by
4 posts views Thread by Robin Haswell | last post: by
12 posts views Thread by manstey | 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.