Unicode short names \ N {} for Latin-1 characters in Python?

Are there short Unicode characters u "\ n {...}" for Latin1 characters in Python? \ n {A umlaut} etc. It would be nice,
\ n {LATIN SMALL LETTER A WITH DIAERESIS} etc. Too long to print every time.
(Added :) I use an English keyboard, but sometimes I need German letters, as in "Löwenbräu Weißbier".
Yes, you can cut-paste them separately, L cutpaste ö wenbr cutpaste ä ... but this breaks the flow; I was hoping only for the keyboard.

+3
source share
6 answers

Sorry, no, there is no such thing. In string literals, anyway ... you could build another encoding scheme like HTML:

>>> import HTMLParser
>>> HTMLParser.HTMLParser().unescape(u'a ä b c')
u'a \xe4 b'

But I don’t think it was worth it.

It is unlikely that anyone even uses the notation \Nanyway ... for a random character, notation is permissible \xnn; for more active use, you'd better just type ädirectly and make sure that << 24> is defined in the script by PEP263 . (If you do not have a keyboard layout that can type these diacritical characters directly, get one of them, for example, eurokb on Windows, or using the Compose key on Linux.)

+3
source

, , UTF-8 python. .

Python UTF-8, , , :

#!/usr/bin/python
# -*- coding: UTF-8 -*-

, Python 3.0 UTF-8 , . . PEP3120

+3

"ä" .

#!/usr/bin/env python
# encoding: utf-8

x = u"ä" 
+1

? -, , \N {A umlaut} \N {LATIN SMALL LETTER A WITH DIAERESIS} .

0

Unicode \uXXXX :

u"\u00E4"
0

On Windows, you can use the charmap.exe utility to search for keyboard shortcuts for the regular letters you use, such as:

ALT-0223 = ß
ALT-0228 = ä
ALT-0246 = ö

Then use Unicode and save in UTF-8:

# -*- coding: UTF-8 -*-
phrase = u'Löwenbräu Weißbier'

or use a converter like someone else mentioned and create your own shortcuts:

# -*- coding: UTF-8 -*-

def german(s):
    s = s.replace(u'SS',u'ß')
    s = s.replace(u'a:',u'ä')
    s = s.replace(u'o:',u'ö')
    return s

phrase = german(u'Lo:wenbra:u WeiSSbier')
print phrase
0
source

Source: https://habr.com/ru/post/1726611/


All Articles