Найти - Пользователи
Полная версия: Символ в юникоде из его кода.
Начало » Python для новичков » Символ в юникоде из его кода.
1
asilyator
Для байтового символа есть chr() и “%с”, а для юникода? Ок, есть unichr(), а форматная строка?

fata1ex
Используйте str.format. (pep3101)

>>> s = u'abc'
>>> type(s)
<type 'unicode'>
>>> print 'unicode - %s' % (s,)
unicode - abc
reclosedev
Python 2.7.3
In [1]: '%c' % 123
Out[1]: '{'
In [2]: u'%c' % 123
Out[2]: u'{'
In [3]: u'%c' % 0x439
Out[3]: u'\u0439'
In [4]: print u'%c' % 0x439
й
In [5]: '%c' % 0x439
---------------------------------------------------------------------------
OverflowError                             Traceback (most recent call last)
----> 1 '%c' % 0x439
OverflowError: unsigned byte integer is greater than maximum

Python 3.2.2
>>> '%c' % 0x0439
'й'
>>> '%c' % 123
'{'
>>>

asilyator
reclosedev, в натуре работает :)
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB