/
usr
/
share
/
doc
/
python3-docs
/
html
/
library
/
/usr/share/doc/python3-docs/html/library
mkdir
upload
Name
Size
Mode
Actions
2to3.html
61709
0644
edit
dl
rm
abc.html
41394
0644
edit
dl
rm
aifc.html
28114
0644
edit
dl
rm
allos.html
32236
0644
edit
dl
rm
archiving.html
11992
0644
edit
dl
rm
argparse.html
274984
0644
edit
dl
rm
array.html
33547
0644
edit
dl
rm
ast.html
39595
0644
edit
dl
rm
asynchat.html
32546
0644
edit
dl
rm
asyncio-dev.html
51869
0644
edit
dl
rm
asyncio-eventloop.html
111215
0644
edit
dl
rm
asyncio-eventloops.html
33026
0644
edit
dl
rm
asyncio-protocol.html
87431
0644
edit
dl
rm
asyncio-queue.html
23957
0644
edit
dl
rm
asyncio-stream.html
61005
0644
edit
dl
rm
asyncio-subprocess.html
58015
0644
edit
dl
rm
asyncio-sync.html
35678
0644
edit
dl
rm
asyncio-task.html
83968
0644
edit
dl
rm
asyncio.html
28026
0644
edit
dl
rm
asyncore.html
42706
0644
edit
dl
rm
atexit.html
18433
0644
edit
dl
rm
audioop.html
35442
0644
edit
dl
rm
base64.html
36454
0644
edit
dl
rm
bdb.html
43423
0644
edit
dl
rm
binary.html
12723
0644
edit
dl
rm
binascii.html
24745
0644
edit
dl
rm
binhex.html
11669
0644
edit
dl
rm
bisect.html
25602
0644
edit
dl
rm
builtins.html
11604
0644
edit
dl
rm
bz2.html
33358
0644
edit
dl
rm
calendar.html
39539
0644
edit
dl
rm
cgi.html
55881
0644
edit
dl
rm
cgitb.html
12765
0644
edit
dl
rm
chunk.html
16872
0644
edit
dl
rm
cmath.html
34171
0644
edit
dl
rm
cmd.html
43811
0644
edit
dl
rm
code.html
27886
0644
edit
dl
rm
codecs.html
134071
0644
edit
dl
rm
codeop.html
14304
0644
edit
dl
rm
collections.abc.html
60912
0644
edit
dl
rm
collections.html
154946
0644
edit
dl
rm
colorsys.html
12627
0644
edit
dl
rm
compileall.html
28263
0644
edit
dl
rm
concurrency.html
21203
0644
edit
dl
rm
concurrent.futures.html
60660
0644
edit
dl
rm
concurrent.html
7959
0644
edit
dl
rm
configparser.html
141052
0644
edit
dl
rm
constants.html
17500
0644
edit
dl
rm
contextlib.html
88801
0644
edit
dl
rm
copy.html
13841
0644
edit
dl
rm
copyreg.html
14725
0644
edit
dl
rm
crypt.html
20331
0644
edit
dl
rm
crypto.html
10914
0644
edit
dl
rm
csv.html
69043
0644
edit
dl
rm
ctypes.html
264529
0644
edit
dl
rm
curses.ascii.html
25197
0644
edit
dl
rm
curses.html
175551
0644
edit
dl
rm
curses.panel.html
16706
0644
edit
dl
rm
custominterp.html
8734
0644
edit
dl
rm
datatypes.html
23950
0644
edit
dl
rm
datetime.html
306435
0644
edit
dl
rm
dbm.html
43119
0644
edit
dl
rm
debug.html
13983
0644
edit
dl
rm
decimal.html
233486
0644
edit
dl
rm
development.html
25123
0644
edit
dl
rm
difflib.html
96156
0644
edit
dl
rm
dis.html
106191
0644
edit
dl
rm
distribution.html
10506
0644
edit
dl
rm
distutils.html
10884
0644
edit
dl
rm
doctest.html
179752
0644
edit
dl
rm
dummy_threading.html
9316
0644
edit
dl
rm
email.charset.html
26431
0644
edit
dl
rm
email.compat32-message.html
86150
0644
edit
dl
rm
email.contentmanager.html
30028
0644
edit
dl
rm
email.encoders.html
14250
0644
edit
dl
rm
email.errors.html
19704
0644
edit
dl
rm
email.examples.html
57872
0644
edit
dl
rm
email.generator.html
41798
0644
edit
dl
rm
email.header.html
31219
0644
edit
dl
rm
email.headerregistry.html
57670
0644
edit
dl
rm
email.html
27741
0644
edit
dl
rm
email.iterators.html
13532
0644
edit
dl
rm
email.message.html
87210
0644
edit
dl
rm
email.mime.html
36081
0644
edit
dl
rm
email.parser.html
47430
0644
edit
dl
rm
email.policy.html
75241
0644
edit
dl
rm
email.util.html
33853
0644
edit
dl
rm
ensurepip.html
18700
0644
edit
dl
rm
enum.html
133949
0644
edit
dl
rm
errno.html
41331
0644
edit
dl
rm
exceptions.html
85151
0644
edit
dl
rm
faulthandler.html
23396
0644
edit
dl
rm
fcntl.html
27321
0644
edit
dl
rm
filecmp.html
25036
0644
edit
dl
rm
fileformats.html
11129
0644
edit
dl
rm
fileinput.html
30030
0644
edit
dl
rm
filesys.html
13418
0644
edit
dl
rm
fnmatch.html
16987
0644
edit
dl
rm
formatter.html
37666
0644
edit
dl
rm
fpectl.html
17538
0644
edit
dl
rm
fractions.html
29918
0644
edit
dl
rm
frameworks.html
13471
0644
edit
dl
rm
ftplib.html
54429
0644
edit
dl
rm
functional.html
9002
0644
edit
dl
rm
functions.html
201486
0644
edit
dl
rm
functools.html
64951
0644
edit
dl
rm
gc.html
29524
0644
edit
dl
rm
getopt.html
25353
0644
edit
dl
rm
getpass.html
12061
0644
edit
dl
rm
gettext.html
76641
0644
edit
dl
rm
glob.html
18432
0644
edit
dl
rm
grp.html
12383
0644
edit
dl
rm
gzip.html
32669
0644
edit
dl
rm
hashlib.html
79554
0644
edit
dl
rm
heapq.html
35529
0644
edit
dl
rm
hmac.html
17827
0644
edit
dl
rm
html.entities.html
11361
0644
edit
dl
rm
html.html
11108
0644
edit
dl
rm
html.parser.html
41842
0644
edit
dl
rm
http.client.html
65250
0644
edit
dl
rm
http.cookiejar.html
96195
0644
edit
dl
rm
http.cookies.html
39329
0644
edit
dl
rm
http.html
37602
0644
edit
dl
rm
http.server.html
58191
0644
edit
dl
rm
i18n.html
10464
0644
edit
dl
rm
idle.html
48412
0644
edit
dl
rm
imaplib.html
67339
0644
edit
dl
rm
imghdr.html
13456
0644
edit
dl
rm
imp.html
48153
0644
edit
dl
rm
importlib.html
173109
0644
edit
dl
rm
index.html
67768
0644
edit
dl
rm
inspect.html
130355
0644
edit
dl
rm
internet.html
31087
0644
edit
dl
rm
intro.html
9904
0644
edit
dl
rm
io.html
122685
0644
edit
dl
rm
ipaddress.html
105873
0644
edit
dl
rm
ipc.html
33743
0644
edit
dl
rm
itertools.html
132824
0644
edit
dl
rm
json.html
81078
0644
edit
dl
rm
keyword.html
8918
0644
edit
dl
rm
language.html
13648
0644
edit
dl
rm
linecache.html
13492
0644
edit
dl
rm
locale.html
61540
0644
edit
dl
rm
logging.config.html
85489
0644
edit
dl
rm
logging.handlers.html
112397
0644
edit
dl
rm
logging.html
134850
0644
edit
dl
rm
lzma.html
56484
0644
edit
dl
rm
macpath.html
9257
0644
edit
dl
rm
mailbox.html
157315
0644
edit
dl
rm
mailcap.html
14676
0644
edit
dl
rm
markup.html
19356
0644
edit
dl
rm
marshal.html
18317
0644
edit
dl
rm
math.html
53661
0644
edit
dl
rm
mimetypes.html
31410
0644
edit
dl
rm
misc.html
8123
0644
edit
dl
rm
mm.html
10022
0644
edit
dl
rm
mmap.html
34294
0644
edit
dl
rm
modulefinder.html
18559
0644
edit
dl
rm
modules.html
10914
0644
edit
dl
rm
msilib.html
57205
0644
edit
dl
rm
msvcrt.html
21989
0644
edit
dl
rm
multiprocessing.html
365487
0644
edit
dl
rm
netdata.html
17470
0644
edit
dl
rm
netrc.html
14568
0644
edit
dl
rm
nis.html
11659
0644
edit
dl
rm
nntplib.html
69601
0644
edit
dl
rm
numbers.html
41432
0644
edit
dl
rm
numeric.html
15535
0644
edit
dl
rm
operator.html
81460
0644
edit
dl
rm
optparse.html
249942
0644
edit
dl
rm
os.html
398039
0644
edit
dl
rm
os.path.html
53818
0644
edit
dl
rm
ossaudiodev.html
47947
0644
edit
dl
rm
othergui.html
10256
0644
edit
dl
rm
parser.html
42408
0644
edit
dl
rm
pathlib.html
116726
0644
edit
dl
rm
pdb.html
52661
0644
edit
dl
rm
persistence.html
15281
0644
edit
dl
rm
pickle.html
115052
0644
edit
dl
rm
pickletools.html
17094
0644
edit
dl
rm
pipes.html
15991
0644
edit
dl
rm
pkgutil.html
31878
0644
edit
dl
rm
platform.html
33728
0644
edit
dl
rm
plistlib.html
29290
0644
edit
dl
rm
poplib.html
30940
0644
edit
dl
rm
posix.html
17608
0644
edit
dl
rm
pprint.html
41969
0644
edit
dl
rm
profile.html
71848
0644
edit
dl
rm
pty.html
17594
0644
edit
dl
rm
pwd.html
13098
0644
edit
dl
rm
pyclbr.html
16520
0644
edit
dl
rm
pydoc.html
15991
0644
edit
dl
rm
pyexpat.html
88938
0644
edit
dl
rm
python.html
17133
0644
edit
dl
rm
py_compile.html
15508
0644
edit
dl
rm
queue.html
28199
0644
edit
dl
rm
quopri.html
13858
0644
edit
dl
rm
random.html
60646
0644
edit
dl
rm
re.html
191176
0644
edit
dl
rm
readline.html
42133
0644
edit
dl
rm
reprlib.html
24964
0644
edit
dl
rm
resource.html
36552
0644
edit
dl
rm
rlcompleter.html
14392
0644
edit
dl
rm
runpy.html
26607
0644
edit
dl
rm
sched.html
20034
0644
edit
dl
rm
secrets.html
24734
0644
edit
dl
rm
select.html
62819
0644
edit
dl
rm
selectors.html
35845
0644
edit
dl
rm
shelve.html
28777
0644
edit
dl
rm
shlex.html
48979
0644
edit
dl
rm
shutil.html
74207
0644
edit
dl
rm
signal.html
55064
0644
edit
dl
rm
site.html
32242
0644
edit
dl
rm
smtpd.html
35892
0644
edit
dl
rm
smtplib.html
68433
0644
edit
dl
rm
sndhdr.html
12439
0644
edit
dl
rm
socket.html
196077
0644
edit
dl
rm
socketserver.html
81918
0644
edit
dl
rm
spwd.html
12328
0644
edit
dl
rm
sqlite3.html
161872
0644
edit
dl
rm
ssl.html
266327
0644
edit
dl
rm
stat.html
44722
0644
edit
dl
rm
statistics.html
50050
0644
edit
dl
rm
stdtypes.html
465658
0644
edit
dl
rm
string.html
95262
0644
edit
dl
rm
stringprep.html
18654
0644
edit
dl
rm
struct.html
51100
0644
edit
dl
rm
subprocess.html
141926
0644
edit
dl
rm
sunau.html
31757
0644
edit
dl
rm
superseded.html
13781
0644
edit
dl
rm
symbol.html
8848
0644
edit
dl
rm
symtable.html
26112
0644
edit
dl
rm
sys.html
141670
0644
edit
dl
rm
sysconfig.html
30259
0644
edit
dl
rm
syslog.html
21026
0644
edit
dl
rm
tabnanny.html
12269
0644
edit
dl
rm
tarfile.html
96758
0644
edit
dl
rm
telnetlib.html
30409
0644
edit
dl
rm
tempfile.html
41394
0644
edit
dl
rm
termios.html
18181
0644
edit
dl
rm
test.html
78555
0644
edit
dl
rm
text.html
13786
0644
edit
dl
rm
textwrap.html
37998
0644
edit
dl
rm
threading.html
103464
0644
edit
dl
rm
time.html
79629
0644
edit
dl
rm
timeit.html
45249
0644
edit
dl
rm
tk.html
23299
0644
edit
dl
rm
tkinter.html
82932
0644
edit
dl
rm
tkinter.scrolledtext.html
9957
0644
edit
dl
rm
tkinter.tix.html
51858
0644
edit
dl
rm
tkinter.ttk.html
110673
0644
edit
dl
rm
token.html
22660
0644
edit
dl
rm
tokenize.html
32149
0644
edit
dl
rm
trace.html
29145
0644
edit
dl
rm
traceback.html
57588
0644
edit
dl
rm
tracemalloc.html
101144
0644
edit
dl
rm
tty.html
10540
0644
edit
dl
rm
turtle.html
250367
0644
edit
dl
rm
types.html
37060
0644
edit
dl
rm
typing.html
139175
0644
edit
dl
rm
undoc.html
9181
0644
edit
dl
rm
unicodedata.html
21108
0644
edit
dl
rm
unittest.html
250689
0644
edit
dl
rm
unittest.mock-examples.html
168144
0644
edit
dl
rm
unittest.mock.html
300089
0644
edit
dl
rm
unix.html
11780
0644
edit
dl
rm
urllib.error.html
14474
0644
edit
dl
rm
urllib.html
9566
0644
edit
dl
rm
urllib.parse.html
76334
0644
edit
dl
rm
urllib.request.html
177199
0644
edit
dl
rm
urllib.robotparser.html
17156
0644
edit
dl
rm
uu.html
12209
0644
edit
dl
rm
uuid.html
31957
0644
edit
dl
rm
venv.html
73909
0644
edit
dl
rm
warnings.html
50320
0644
edit
dl
rm
wave.html
29868
0644
edit
dl
rm
weakref.html
65292
0644
edit
dl
rm
webbrowser.html
26901
0644
edit
dl
rm
windows.html
10626
0644
edit
dl
rm
winreg.html
66730
0644
edit
dl
rm
winsound.html
21268
0644
edit
dl
rm
wsgiref.html
94492
0644
edit
dl
rm
xdrlib.html
33751
0644
edit
dl
rm
xml.dom.html
97570
0644
edit
dl
rm
xml.dom.minidom.html
41481
0644
edit
dl
rm
xml.dom.pulldom.html
24214
0644
edit
dl
rm
xml.etree.elementtree.html
135491
0644
edit
dl
rm
xml.html
19261
0644
edit
dl
rm
xml.sax.handler.html
42659
0644
edit
dl
rm
xml.sax.html
25515
0644
edit
dl
rm
xml.sax.reader.html
45869
0644
edit
dl
rm
xml.sax.utils.html
16928
0644
edit
dl
rm
xmlrpc.client.html
71947
0644
edit
dl
rm
xmlrpc.html
8535
0644
edit
dl
rm
xmlrpc.server.html
49195
0644
edit
dl
rm
zipapp.html
45105
0644
edit
dl
rm
zipfile.html
80039
0644
edit
dl
rm
zipimport.html
23052
0644
edit
dl
rm
zlib.html
34557
0644
edit
dl
rm
_dummy_thread.html
9193
0644
edit
dl
rm
_thread.html
22588
0644
edit
dl
rm
__future__.html
15792
0644
edit
dl
rm
__main__.html
9019
0644
edit
dl
rm
Edit:
/usr/share/doc/python3-docs/html/library/locale.html
(61540B)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="X-UA-Compatible" content="IE=Edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>23.2. locale — Internationalization services — Python 3.6.7 documentation</title> <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/sidebar.js"></script> <link rel="search" type="application/opensearchdescription+xml" title="Search within Python 3.6.7 documentation" href="../_static/opensearch.xml"/> <link rel="author" title="About these documents" href="../about.html" /> <link rel="index" title="Index" href="../genindex.html" /> <link rel="search" title="Search" href="../search.html" /> <link rel="copyright" title="Copyright" href="../copyright.html" /> <link rel="next" title="24. Program Frameworks" href="frameworks.html" /> <link rel="prev" title="23.1. gettext — Multilingual internationalization services" href="gettext.html" /> <link rel="shortcut icon" type="image/png" href="../_static/py.png" /> <link rel="canonical" href="https://docs.python.org/3/library/locale.html" /> <script type="text/javascript" src="../_static/copybutton.js"></script> </head><body> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="frameworks.html" title="24. Program Frameworks" accesskey="N">next</a> |</li> <li class="right" > <a href="gettext.html" title="23.1. gettext — Multilingual internationalization services" accesskey="P">previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="https://www.python.org/">Python</a> »</li> <li> <a href="../index.html">3.6.7 Documentation</a> » </li> <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li> <li class="nav-item nav-item-2"><a href="i18n.html" accesskey="U">23. Internationalization</a> »</li> <li class="right"> <div class="inline-search" style="display: none" role="search"> <form class="inline-search" action="../search.html" method="get"> <input placeholder="Quick search" type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </div> <script type="text/javascript">$('.inline-search').show(0);</script> | </li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body" role="main"> <div class="section" id="module-locale"> <span id="locale-internationalization-services"></span><h1>23.2. <a class="reference internal" href="#module-locale" title="locale: Internationalization services."><code class="xref py py-mod docutils literal notranslate"><span class="pre">locale</span></code></a> — Internationalization services<a class="headerlink" href="#module-locale" title="Permalink to this headline">¶</a></h1> <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.6/Lib/locale.py">Lib/locale.py</a></p> <hr class="docutils" /> <p>The <a class="reference internal" href="#module-locale" title="locale: Internationalization services."><code class="xref py py-mod docutils literal notranslate"><span class="pre">locale</span></code></a> module opens access to the POSIX locale database and functionality. The POSIX locale mechanism allows programmers to deal with certain cultural issues in an application, without requiring the programmer to know all the specifics of each country where the software is executed.</p> <p id="index-0">The <a class="reference internal" href="#module-locale" title="locale: Internationalization services."><code class="xref py py-mod docutils literal notranslate"><span class="pre">locale</span></code></a> module is implemented on top of the <code class="xref py py-mod docutils literal notranslate"><span class="pre">_locale</span></code> module, which in turn uses an ANSI C locale implementation if available.</p> <p>The <a class="reference internal" href="#module-locale" title="locale: Internationalization services."><code class="xref py py-mod docutils literal notranslate"><span class="pre">locale</span></code></a> module defines the following exception and functions:</p> <dl class="exception"> <dt id="locale.Error"> <em class="property">exception </em><code class="descclassname">locale.</code><code class="descname">Error</code><a class="headerlink" href="#locale.Error" title="Permalink to this definition">¶</a></dt> <dd><p>Exception raised when the locale passed to <a class="reference internal" href="#locale.setlocale" title="locale.setlocale"><code class="xref py py-func docutils literal notranslate"><span class="pre">setlocale()</span></code></a> is not recognized.</p> </dd></dl> <dl class="function"> <dt id="locale.setlocale"> <code class="descclassname">locale.</code><code class="descname">setlocale</code><span class="sig-paren">(</span><em>category</em>, <em>locale=None</em><span class="sig-paren">)</span><a class="headerlink" href="#locale.setlocale" title="Permalink to this definition">¶</a></dt> <dd><p>If <em>locale</em> is given and not <code class="docutils literal notranslate"><span class="pre">None</span></code>, <a class="reference internal" href="#locale.setlocale" title="locale.setlocale"><code class="xref py py-func docutils literal notranslate"><span class="pre">setlocale()</span></code></a> modifies the locale setting for the <em>category</em>. The available categories are listed in the data description below. <em>locale</em> may be a string, or an iterable of two strings (language code and encoding). If it’s an iterable, it’s converted to a locale name using the locale aliasing engine. An empty string specifies the user’s default settings. If the modification of the locale fails, the exception <a class="reference internal" href="#locale.Error" title="locale.Error"><code class="xref py py-exc docutils literal notranslate"><span class="pre">Error</span></code></a> is raised. If successful, the new locale setting is returned.</p> <p>If <em>locale</em> is omitted or <code class="docutils literal notranslate"><span class="pre">None</span></code>, the current setting for <em>category</em> is returned.</p> <p><a class="reference internal" href="#locale.setlocale" title="locale.setlocale"><code class="xref py py-func docutils literal notranslate"><span class="pre">setlocale()</span></code></a> is not thread-safe on most systems. Applications typically start with a call of</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">locale</span> <span class="n">locale</span><span class="o">.</span><span class="n">setlocale</span><span class="p">(</span><span class="n">locale</span><span class="o">.</span><span class="n">LC_ALL</span><span class="p">,</span> <span class="s1">''</span><span class="p">)</span> </pre></div> </div> <p>This sets the locale for all categories to the user’s default setting (typically specified in the <span class="target" id="index-1"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">LANG</span></code> environment variable). If the locale is not changed thereafter, using multithreading should not cause problems.</p> </dd></dl> <dl class="function"> <dt id="locale.localeconv"> <code class="descclassname">locale.</code><code class="descname">localeconv</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#locale.localeconv" title="Permalink to this definition">¶</a></dt> <dd><p>Returns the database of the local conventions as a dictionary. This dictionary has the following strings as keys:</p> <table border="1" class="docutils"> <colgroup> <col width="24%" /> <col width="41%" /> <col width="35%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head">Category</th> <th class="head">Key</th> <th class="head">Meaning</th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td><a class="reference internal" href="#locale.LC_NUMERIC" title="locale.LC_NUMERIC"><code class="xref py py-const docutils literal notranslate"><span class="pre">LC_NUMERIC</span></code></a></td> <td><code class="docutils literal notranslate"><span class="pre">'decimal_point'</span></code></td> <td>Decimal point character.</td> </tr> <tr class="row-odd"><td> </td> <td><code class="docutils literal notranslate"><span class="pre">'grouping'</span></code></td> <td>Sequence of numbers specifying which relative positions the <code class="docutils literal notranslate"><span class="pre">'thousands_sep'</span></code> is expected. If the sequence is terminated with <a class="reference internal" href="#locale.CHAR_MAX" title="locale.CHAR_MAX"><code class="xref py py-const docutils literal notranslate"><span class="pre">CHAR_MAX</span></code></a>, no further grouping is performed. If the sequence terminates with a <code class="docutils literal notranslate"><span class="pre">0</span></code>, the last group size is repeatedly used.</td> </tr> <tr class="row-even"><td> </td> <td><code class="docutils literal notranslate"><span class="pre">'thousands_sep'</span></code></td> <td>Character used between groups.</td> </tr> <tr class="row-odd"><td><a class="reference internal" href="#locale.LC_MONETARY" title="locale.LC_MONETARY"><code class="xref py py-const docutils literal notranslate"><span class="pre">LC_MONETARY</span></code></a></td> <td><code class="docutils literal notranslate"><span class="pre">'int_curr_symbol'</span></code></td> <td>International currency symbol.</td> </tr> <tr class="row-even"><td> </td> <td><code class="docutils literal notranslate"><span class="pre">'currency_symbol'</span></code></td> <td>Local currency symbol.</td> </tr> <tr class="row-odd"><td> </td> <td><code class="docutils literal notranslate"><span class="pre">'p_cs_precedes/n_cs_precedes'</span></code></td> <td>Whether the currency symbol precedes the value (for positive resp. negative values).</td> </tr> <tr class="row-even"><td> </td> <td><code class="docutils literal notranslate"><span class="pre">'p_sep_by_space/n_sep_by_space'</span></code></td> <td>Whether the currency symbol is separated from the value by a space (for positive resp. negative values).</td> </tr> <tr class="row-odd"><td> </td> <td><code class="docutils literal notranslate"><span class="pre">'mon_decimal_point'</span></code></td> <td>Decimal point used for monetary values.</td> </tr> <tr class="row-even"><td> </td> <td><code class="docutils literal notranslate"><span class="pre">'frac_digits'</span></code></td> <td>Number of fractional digits used in local formatting of monetary values.</td> </tr> <tr class="row-odd"><td> </td> <td><code class="docutils literal notranslate"><span class="pre">'int_frac_digits'</span></code></td> <td>Number of fractional digits used in international formatting of monetary values.</td> </tr> <tr class="row-even"><td> </td> <td><code class="docutils literal notranslate"><span class="pre">'mon_thousands_sep'</span></code></td> <td>Group separator used for monetary values.</td> </tr> <tr class="row-odd"><td> </td> <td><code class="docutils literal notranslate"><span class="pre">'mon_grouping'</span></code></td> <td>Equivalent to <code class="docutils literal notranslate"><span class="pre">'grouping'</span></code>, used for monetary values.</td> </tr> <tr class="row-even"><td> </td> <td><code class="docutils literal notranslate"><span class="pre">'positive_sign'</span></code></td> <td>Symbol used to annotate a positive monetary value.</td> </tr> <tr class="row-odd"><td> </td> <td><code class="docutils literal notranslate"><span class="pre">'negative_sign'</span></code></td> <td>Symbol used to annotate a negative monetary value.</td> </tr> <tr class="row-even"><td> </td> <td><code class="docutils literal notranslate"><span class="pre">'p_sign_posn/n_sign_posn'</span></code></td> <td>The position of the sign (for positive resp. negative values), see below.</td> </tr> </tbody> </table> <p>All numeric values can be set to <a class="reference internal" href="#locale.CHAR_MAX" title="locale.CHAR_MAX"><code class="xref py py-const docutils literal notranslate"><span class="pre">CHAR_MAX</span></code></a> to indicate that there is no value specified in this locale.</p> <p>The possible values for <code class="docutils literal notranslate"><span class="pre">'p_sign_posn'</span></code> and <code class="docutils literal notranslate"><span class="pre">'n_sign_posn'</span></code> are given below.</p> <table border="1" class="docutils"> <colgroup> <col width="25%" /> <col width="75%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head">Value</th> <th class="head">Explanation</th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td><code class="docutils literal notranslate"><span class="pre">0</span></code></td> <td>Currency and value are surrounded by parentheses.</td> </tr> <tr class="row-odd"><td><code class="docutils literal notranslate"><span class="pre">1</span></code></td> <td>The sign should precede the value and currency symbol.</td> </tr> <tr class="row-even"><td><code class="docutils literal notranslate"><span class="pre">2</span></code></td> <td>The sign should follow the value and currency symbol.</td> </tr> <tr class="row-odd"><td><code class="docutils literal notranslate"><span class="pre">3</span></code></td> <td>The sign should immediately precede the value.</td> </tr> <tr class="row-even"><td><code class="docutils literal notranslate"><span class="pre">4</span></code></td> <td>The sign should immediately follow the value.</td> </tr> <tr class="row-odd"><td><code class="docutils literal notranslate"><span class="pre">CHAR_MAX</span></code></td> <td>Nothing is specified in this locale.</td> </tr> </tbody> </table> <p>The function sets temporarily the <code class="docutils literal notranslate"><span class="pre">LC_CTYPE</span></code> locale to the <code class="docutils literal notranslate"><span class="pre">LC_NUMERIC</span></code> locale to decode <code class="docutils literal notranslate"><span class="pre">decimal_point</span></code> and <code class="docutils literal notranslate"><span class="pre">thousands_sep</span></code> byte strings if they are non-ASCII or longer than 1 byte, and the <code class="docutils literal notranslate"><span class="pre">LC_NUMERIC</span></code> locale is different than the <code class="docutils literal notranslate"><span class="pre">LC_CTYPE</span></code> locale. This temporary change affects other threads.</p> <div class="versionchanged"> <p><span class="versionmodified">Changed in version 3.6.5: </span>The function now sets temporarily the <code class="docutils literal notranslate"><span class="pre">LC_CTYPE</span></code> locale to the <code class="docutils literal notranslate"><span class="pre">LC_NUMERIC</span></code> locale in some cases.</p> </div> </dd></dl> <dl class="function"> <dt id="locale.nl_langinfo"> <code class="descclassname">locale.</code><code class="descname">nl_langinfo</code><span class="sig-paren">(</span><em>option</em><span class="sig-paren">)</span><a class="headerlink" href="#locale.nl_langinfo" title="Permalink to this definition">¶</a></dt> <dd><p>Return some locale-specific information as a string. This function is not available on all systems, and the set of possible options might also vary across platforms. The possible argument values are numbers, for which symbolic constants are available in the locale module.</p> <p>The <a class="reference internal" href="#locale.nl_langinfo" title="locale.nl_langinfo"><code class="xref py py-func docutils literal notranslate"><span class="pre">nl_langinfo()</span></code></a> function accepts one of the following keys. Most descriptions are taken from the corresponding description in the GNU C library.</p> <dl class="data"> <dt id="locale.CODESET"> <code class="descclassname">locale.</code><code class="descname">CODESET</code><a class="headerlink" href="#locale.CODESET" title="Permalink to this definition">¶</a></dt> <dd><p>Get a string with the name of the character encoding used in the selected locale.</p> </dd></dl> <dl class="data"> <dt id="locale.D_T_FMT"> <code class="descclassname">locale.</code><code class="descname">D_T_FMT</code><a class="headerlink" href="#locale.D_T_FMT" title="Permalink to this definition">¶</a></dt> <dd><p>Get a string that can be used as a format string for <a class="reference internal" href="time.html#time.strftime" title="time.strftime"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.strftime()</span></code></a> to represent date and time in a locale-specific way.</p> </dd></dl> <dl class="data"> <dt id="locale.D_FMT"> <code class="descclassname">locale.</code><code class="descname">D_FMT</code><a class="headerlink" href="#locale.D_FMT" title="Permalink to this definition">¶</a></dt> <dd><p>Get a string that can be used as a format string for <a class="reference internal" href="time.html#time.strftime" title="time.strftime"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.strftime()</span></code></a> to represent a date in a locale-specific way.</p> </dd></dl> <dl class="data"> <dt id="locale.T_FMT"> <code class="descclassname">locale.</code><code class="descname">T_FMT</code><a class="headerlink" href="#locale.T_FMT" title="Permalink to this definition">¶</a></dt> <dd><p>Get a string that can be used as a format string for <a class="reference internal" href="time.html#time.strftime" title="time.strftime"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.strftime()</span></code></a> to represent a time in a locale-specific way.</p> </dd></dl> <dl class="data"> <dt id="locale.T_FMT_AMPM"> <code class="descclassname">locale.</code><code class="descname">T_FMT_AMPM</code><a class="headerlink" href="#locale.T_FMT_AMPM" title="Permalink to this definition">¶</a></dt> <dd><p>Get a format string for <a class="reference internal" href="time.html#time.strftime" title="time.strftime"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.strftime()</span></code></a> to represent time in the am/pm format.</p> </dd></dl> <dl class="data"> <dt> <code class="descname">DAY_1 ... DAY_7</code></dt> <dd><p>Get the name of the n-th day of the week.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">This follows the US convention of <code class="xref py py-const docutils literal notranslate"><span class="pre">DAY_1</span></code> being Sunday, not the international convention (ISO 8601) that Monday is the first day of the week.</p> </div> </dd></dl> <dl class="data"> <dt> <code class="descname">ABDAY_1 ... ABDAY_7</code></dt> <dd><p>Get the abbreviated name of the n-th day of the week.</p> </dd></dl> <dl class="data"> <dt> <code class="descname">MON_1 ... MON_12</code></dt> <dd><p>Get the name of the n-th month.</p> </dd></dl> <dl class="data"> <dt> <code class="descname">ABMON_1 ... ABMON_12</code></dt> <dd><p>Get the abbreviated name of the n-th month.</p> </dd></dl> <dl class="data"> <dt id="locale.RADIXCHAR"> <code class="descclassname">locale.</code><code class="descname">RADIXCHAR</code><a class="headerlink" href="#locale.RADIXCHAR" title="Permalink to this definition">¶</a></dt> <dd><p>Get the radix character (decimal dot, decimal comma, etc.).</p> </dd></dl> <dl class="data"> <dt id="locale.THOUSEP"> <code class="descclassname">locale.</code><code class="descname">THOUSEP</code><a class="headerlink" href="#locale.THOUSEP" title="Permalink to this definition">¶</a></dt> <dd><p>Get the separator character for thousands (groups of three digits).</p> </dd></dl> <dl class="data"> <dt id="locale.YESEXPR"> <code class="descclassname">locale.</code><code class="descname">YESEXPR</code><a class="headerlink" href="#locale.YESEXPR" title="Permalink to this definition">¶</a></dt> <dd><p>Get a regular expression that can be used with the regex function to recognize a positive response to a yes/no question.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">The expression is in the syntax suitable for the <code class="xref c c-func docutils literal notranslate"><span class="pre">regex()</span></code> function from the C library, which might differ from the syntax used in <a class="reference internal" href="re.html#module-re" title="re: Regular expression operations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">re</span></code></a>.</p> </div> </dd></dl> <dl class="data"> <dt id="locale.NOEXPR"> <code class="descclassname">locale.</code><code class="descname">NOEXPR</code><a class="headerlink" href="#locale.NOEXPR" title="Permalink to this definition">¶</a></dt> <dd><p>Get a regular expression that can be used with the regex(3) function to recognize a negative response to a yes/no question.</p> </dd></dl> <dl class="data"> <dt id="locale.CRNCYSTR"> <code class="descclassname">locale.</code><code class="descname">CRNCYSTR</code><a class="headerlink" href="#locale.CRNCYSTR" title="Permalink to this definition">¶</a></dt> <dd><p>Get the currency symbol, preceded by “-” if the symbol should appear before the value, “+” if the symbol should appear after the value, or “.” if the symbol should replace the radix character.</p> </dd></dl> <dl class="data"> <dt id="locale.ERA"> <code class="descclassname">locale.</code><code class="descname">ERA</code><a class="headerlink" href="#locale.ERA" title="Permalink to this definition">¶</a></dt> <dd><p>Get a string that represents the era used in the current locale.</p> <p>Most locales do not define this value. An example of a locale which does define this value is the Japanese one. In Japan, the traditional representation of dates includes the name of the era corresponding to the then-emperor’s reign.</p> <p>Normally it should not be necessary to use this value directly. Specifying the <code class="docutils literal notranslate"><span class="pre">E</span></code> modifier in their format strings causes the <a class="reference internal" href="time.html#time.strftime" title="time.strftime"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.strftime()</span></code></a> function to use this information. The format of the returned string is not specified, and therefore you should not assume knowledge of it on different systems.</p> </dd></dl> <dl class="data"> <dt id="locale.ERA_D_T_FMT"> <code class="descclassname">locale.</code><code class="descname">ERA_D_T_FMT</code><a class="headerlink" href="#locale.ERA_D_T_FMT" title="Permalink to this definition">¶</a></dt> <dd><p>Get a format string for <a class="reference internal" href="time.html#time.strftime" title="time.strftime"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.strftime()</span></code></a> to represent date and time in a locale-specific era-based way.</p> </dd></dl> <dl class="data"> <dt id="locale.ERA_D_FMT"> <code class="descclassname">locale.</code><code class="descname">ERA_D_FMT</code><a class="headerlink" href="#locale.ERA_D_FMT" title="Permalink to this definition">¶</a></dt> <dd><p>Get a format string for <a class="reference internal" href="time.html#time.strftime" title="time.strftime"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.strftime()</span></code></a> to represent a date in a locale-specific era-based way.</p> </dd></dl> <dl class="data"> <dt id="locale.ERA_T_FMT"> <code class="descclassname">locale.</code><code class="descname">ERA_T_FMT</code><a class="headerlink" href="#locale.ERA_T_FMT" title="Permalink to this definition">¶</a></dt> <dd><p>Get a format string for <a class="reference internal" href="time.html#time.strftime" title="time.strftime"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.strftime()</span></code></a> to represent a time in a locale-specific era-based way.</p> </dd></dl> <dl class="data"> <dt id="locale.ALT_DIGITS"> <code class="descclassname">locale.</code><code class="descname">ALT_DIGITS</code><a class="headerlink" href="#locale.ALT_DIGITS" title="Permalink to this definition">¶</a></dt> <dd><p>Get a representation of up to 100 values used to represent the values 0 to 99.</p> </dd></dl> </dd></dl> <dl class="function"> <dt id="locale.getdefaultlocale"> <code class="descclassname">locale.</code><code class="descname">getdefaultlocale</code><span class="sig-paren">(</span><span class="optional">[</span><em>envvars</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#locale.getdefaultlocale" title="Permalink to this definition">¶</a></dt> <dd><p>Tries to determine the default locale settings and returns them as a tuple of the form <code class="docutils literal notranslate"><span class="pre">(language</span> <span class="pre">code,</span> <span class="pre">encoding)</span></code>.</p> <p>According to POSIX, a program which has not called <code class="docutils literal notranslate"><span class="pre">setlocale(LC_ALL,</span> <span class="pre">'')</span></code> runs using the portable <code class="docutils literal notranslate"><span class="pre">'C'</span></code> locale. Calling <code class="docutils literal notranslate"><span class="pre">setlocale(LC_ALL,</span> <span class="pre">'')</span></code> lets it use the default locale as defined by the <span class="target" id="index-2"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">LANG</span></code> variable. Since we do not want to interfere with the current locale setting we thus emulate the behavior in the way described above.</p> <p>To maintain compatibility with other platforms, not only the <span class="target" id="index-3"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">LANG</span></code> variable is tested, but a list of variables given as envvars parameter. The first found to be defined will be used. <em>envvars</em> defaults to the search path used in GNU gettext; it must always contain the variable name <code class="docutils literal notranslate"><span class="pre">'LANG'</span></code>. The GNU gettext search path contains <code class="docutils literal notranslate"><span class="pre">'LC_ALL'</span></code>, <code class="docutils literal notranslate"><span class="pre">'LC_CTYPE'</span></code>, <code class="docutils literal notranslate"><span class="pre">'LANG'</span></code> and <code class="docutils literal notranslate"><span class="pre">'LANGUAGE'</span></code>, in that order.</p> <p>Except for the code <code class="docutils literal notranslate"><span class="pre">'C'</span></code>, the language code corresponds to <span class="target" id="index-4"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc1766.html"><strong>RFC 1766</strong></a>. <em>language code</em> and <em>encoding</em> may be <code class="docutils literal notranslate"><span class="pre">None</span></code> if their values cannot be determined.</p> </dd></dl> <dl class="function"> <dt id="locale.getlocale"> <code class="descclassname">locale.</code><code class="descname">getlocale</code><span class="sig-paren">(</span><em>category=LC_CTYPE</em><span class="sig-paren">)</span><a class="headerlink" href="#locale.getlocale" title="Permalink to this definition">¶</a></dt> <dd><p>Returns the current setting for the given locale category as sequence containing <em>language code</em>, <em>encoding</em>. <em>category</em> may be one of the <code class="xref py py-const docutils literal notranslate"><span class="pre">LC_*</span></code> values except <a class="reference internal" href="#locale.LC_ALL" title="locale.LC_ALL"><code class="xref py py-const docutils literal notranslate"><span class="pre">LC_ALL</span></code></a>. It defaults to <a class="reference internal" href="#locale.LC_CTYPE" title="locale.LC_CTYPE"><code class="xref py py-const docutils literal notranslate"><span class="pre">LC_CTYPE</span></code></a>.</p> <p>Except for the code <code class="docutils literal notranslate"><span class="pre">'C'</span></code>, the language code corresponds to <span class="target" id="index-5"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc1766.html"><strong>RFC 1766</strong></a>. <em>language code</em> and <em>encoding</em> may be <code class="docutils literal notranslate"><span class="pre">None</span></code> if their values cannot be determined.</p> </dd></dl> <dl class="function"> <dt id="locale.getpreferredencoding"> <code class="descclassname">locale.</code><code class="descname">getpreferredencoding</code><span class="sig-paren">(</span><em>do_setlocale=True</em><span class="sig-paren">)</span><a class="headerlink" href="#locale.getpreferredencoding" title="Permalink to this definition">¶</a></dt> <dd><p>Return the encoding used for text data, according to user preferences. User preferences are expressed differently on different systems, and might not be available programmatically on some systems, so this function only returns a guess.</p> <p>On some systems, it is necessary to invoke <a class="reference internal" href="#locale.setlocale" title="locale.setlocale"><code class="xref py py-func docutils literal notranslate"><span class="pre">setlocale()</span></code></a> to obtain the user preferences, so this function is not thread-safe. If invoking setlocale is not necessary or desired, <em>do_setlocale</em> should be set to <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p> </dd></dl> <dl class="function"> <dt id="locale.normalize"> <code class="descclassname">locale.</code><code class="descname">normalize</code><span class="sig-paren">(</span><em>localename</em><span class="sig-paren">)</span><a class="headerlink" href="#locale.normalize" title="Permalink to this definition">¶</a></dt> <dd><p>Returns a normalized locale code for the given locale name. The returned locale code is formatted for use with <a class="reference internal" href="#locale.setlocale" title="locale.setlocale"><code class="xref py py-func docutils literal notranslate"><span class="pre">setlocale()</span></code></a>. If normalization fails, the original name is returned unchanged.</p> <p>If the given encoding is not known, the function defaults to the default encoding for the locale code just like <a class="reference internal" href="#locale.setlocale" title="locale.setlocale"><code class="xref py py-func docutils literal notranslate"><span class="pre">setlocale()</span></code></a>.</p> </dd></dl> <dl class="function"> <dt id="locale.resetlocale"> <code class="descclassname">locale.</code><code class="descname">resetlocale</code><span class="sig-paren">(</span><em>category=LC_ALL</em><span class="sig-paren">)</span><a class="headerlink" href="#locale.resetlocale" title="Permalink to this definition">¶</a></dt> <dd><p>Sets the locale for <em>category</em> to the default setting.</p> <p>The default setting is determined by calling <a class="reference internal" href="#locale.getdefaultlocale" title="locale.getdefaultlocale"><code class="xref py py-func docutils literal notranslate"><span class="pre">getdefaultlocale()</span></code></a>. <em>category</em> defaults to <a class="reference internal" href="#locale.LC_ALL" title="locale.LC_ALL"><code class="xref py py-const docutils literal notranslate"><span class="pre">LC_ALL</span></code></a>.</p> </dd></dl> <dl class="function"> <dt id="locale.strcoll"> <code class="descclassname">locale.</code><code class="descname">strcoll</code><span class="sig-paren">(</span><em>string1</em>, <em>string2</em><span class="sig-paren">)</span><a class="headerlink" href="#locale.strcoll" title="Permalink to this definition">¶</a></dt> <dd><p>Compares two strings according to the current <a class="reference internal" href="#locale.LC_COLLATE" title="locale.LC_COLLATE"><code class="xref py py-const docutils literal notranslate"><span class="pre">LC_COLLATE</span></code></a> setting. As any other compare function, returns a negative, or a positive value, or <code class="docutils literal notranslate"><span class="pre">0</span></code>, depending on whether <em>string1</em> collates before or after <em>string2</em> or is equal to it.</p> </dd></dl> <dl class="function"> <dt id="locale.strxfrm"> <code class="descclassname">locale.</code><code class="descname">strxfrm</code><span class="sig-paren">(</span><em>string</em><span class="sig-paren">)</span><a class="headerlink" href="#locale.strxfrm" title="Permalink to this definition">¶</a></dt> <dd><p>Transforms a string to one that can be used in locale-aware comparisons. For example, <code class="docutils literal notranslate"><span class="pre">strxfrm(s1)</span> <span class="pre"><</span> <span class="pre">strxfrm(s2)</span></code> is equivalent to <code class="docutils literal notranslate"><span class="pre">strcoll(s1,</span> <span class="pre">s2)</span> <span class="pre"><</span> <span class="pre">0</span></code>. This function can be used when the same string is compared repeatedly, e.g. when collating a sequence of strings.</p> </dd></dl> <dl class="function"> <dt id="locale.format"> <code class="descclassname">locale.</code><code class="descname">format</code><span class="sig-paren">(</span><em>format</em>, <em>val</em>, <em>grouping=False</em>, <em>monetary=False</em><span class="sig-paren">)</span><a class="headerlink" href="#locale.format" title="Permalink to this definition">¶</a></dt> <dd><p>Formats a number <em>val</em> according to the current <a class="reference internal" href="#locale.LC_NUMERIC" title="locale.LC_NUMERIC"><code class="xref py py-const docutils literal notranslate"><span class="pre">LC_NUMERIC</span></code></a> setting. The format follows the conventions of the <code class="docutils literal notranslate"><span class="pre">%</span></code> operator. For floating point values, the decimal point is modified if appropriate. If <em>grouping</em> is true, also takes the grouping into account.</p> <p>If <em>monetary</em> is true, the conversion uses monetary thousands separator and grouping strings.</p> <p>Please note that this function will only work for exactly one %char specifier. For whole format strings, use <a class="reference internal" href="#locale.format_string" title="locale.format_string"><code class="xref py py-func docutils literal notranslate"><span class="pre">format_string()</span></code></a>.</p> </dd></dl> <dl class="function"> <dt id="locale.format_string"> <code class="descclassname">locale.</code><code class="descname">format_string</code><span class="sig-paren">(</span><em>format</em>, <em>val</em>, <em>grouping=False</em><span class="sig-paren">)</span><a class="headerlink" href="#locale.format_string" title="Permalink to this definition">¶</a></dt> <dd><p>Processes formatting specifiers as in <code class="docutils literal notranslate"><span class="pre">format</span> <span class="pre">%</span> <span class="pre">val</span></code>, but takes the current locale settings into account.</p> </dd></dl> <dl class="function"> <dt id="locale.currency"> <code class="descclassname">locale.</code><code class="descname">currency</code><span class="sig-paren">(</span><em>val</em>, <em>symbol=True</em>, <em>grouping=False</em>, <em>international=False</em><span class="sig-paren">)</span><a class="headerlink" href="#locale.currency" title="Permalink to this definition">¶</a></dt> <dd><p>Formats a number <em>val</em> according to the current <a class="reference internal" href="#locale.LC_MONETARY" title="locale.LC_MONETARY"><code class="xref py py-const docutils literal notranslate"><span class="pre">LC_MONETARY</span></code></a> settings.</p> <p>The returned string includes the currency symbol if <em>symbol</em> is true, which is the default. If <em>grouping</em> is true (which is not the default), grouping is done with the value. If <em>international</em> is true (which is not the default), the international currency symbol is used.</p> <p>Note that this function will not work with the ‘C’ locale, so you have to set a locale via <a class="reference internal" href="#locale.setlocale" title="locale.setlocale"><code class="xref py py-func docutils literal notranslate"><span class="pre">setlocale()</span></code></a> first.</p> </dd></dl> <dl class="function"> <dt id="locale.str"> <code class="descclassname">locale.</code><code class="descname">str</code><span class="sig-paren">(</span><em>float</em><span class="sig-paren">)</span><a class="headerlink" href="#locale.str" title="Permalink to this definition">¶</a></dt> <dd><p>Formats a floating point number using the same format as the built-in function <code class="docutils literal notranslate"><span class="pre">str(float)</span></code>, but takes the decimal point into account.</p> </dd></dl> <dl class="function"> <dt id="locale.delocalize"> <code class="descclassname">locale.</code><code class="descname">delocalize</code><span class="sig-paren">(</span><em>string</em><span class="sig-paren">)</span><a class="headerlink" href="#locale.delocalize" title="Permalink to this definition">¶</a></dt> <dd><p>Converts a string into a normalized number string, following the <a class="reference internal" href="#locale.LC_NUMERIC" title="locale.LC_NUMERIC"><code class="xref py py-const docutils literal notranslate"><span class="pre">LC_NUMERIC</span></code></a> settings.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.5.</span></p> </div> </dd></dl> <dl class="function"> <dt id="locale.atof"> <code class="descclassname">locale.</code><code class="descname">atof</code><span class="sig-paren">(</span><em>string</em><span class="sig-paren">)</span><a class="headerlink" href="#locale.atof" title="Permalink to this definition">¶</a></dt> <dd><p>Converts a string to a floating point number, following the <a class="reference internal" href="#locale.LC_NUMERIC" title="locale.LC_NUMERIC"><code class="xref py py-const docutils literal notranslate"><span class="pre">LC_NUMERIC</span></code></a> settings.</p> </dd></dl> <dl class="function"> <dt id="locale.atoi"> <code class="descclassname">locale.</code><code class="descname">atoi</code><span class="sig-paren">(</span><em>string</em><span class="sig-paren">)</span><a class="headerlink" href="#locale.atoi" title="Permalink to this definition">¶</a></dt> <dd><p>Converts a string to an integer, following the <a class="reference internal" href="#locale.LC_NUMERIC" title="locale.LC_NUMERIC"><code class="xref py py-const docutils literal notranslate"><span class="pre">LC_NUMERIC</span></code></a> conventions.</p> </dd></dl> <dl class="data"> <dt id="locale.LC_CTYPE"> <code class="descclassname">locale.</code><code class="descname">LC_CTYPE</code><a class="headerlink" href="#locale.LC_CTYPE" title="Permalink to this definition">¶</a></dt> <dd><p id="index-6">Locale category for the character type functions. Depending on the settings of this category, the functions of module <a class="reference internal" href="string.html#module-string" title="string: Common string operations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">string</span></code></a> dealing with case change their behaviour.</p> </dd></dl> <dl class="data"> <dt id="locale.LC_COLLATE"> <code class="descclassname">locale.</code><code class="descname">LC_COLLATE</code><a class="headerlink" href="#locale.LC_COLLATE" title="Permalink to this definition">¶</a></dt> <dd><p>Locale category for sorting strings. The functions <a class="reference internal" href="#locale.strcoll" title="locale.strcoll"><code class="xref py py-func docutils literal notranslate"><span class="pre">strcoll()</span></code></a> and <a class="reference internal" href="#locale.strxfrm" title="locale.strxfrm"><code class="xref py py-func docutils literal notranslate"><span class="pre">strxfrm()</span></code></a> of the <a class="reference internal" href="#module-locale" title="locale: Internationalization services."><code class="xref py py-mod docutils literal notranslate"><span class="pre">locale</span></code></a> module are affected.</p> </dd></dl> <dl class="data"> <dt id="locale.LC_TIME"> <code class="descclassname">locale.</code><code class="descname">LC_TIME</code><a class="headerlink" href="#locale.LC_TIME" title="Permalink to this definition">¶</a></dt> <dd><p>Locale category for the formatting of time. The function <a class="reference internal" href="time.html#time.strftime" title="time.strftime"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.strftime()</span></code></a> follows these conventions.</p> </dd></dl> <dl class="data"> <dt id="locale.LC_MONETARY"> <code class="descclassname">locale.</code><code class="descname">LC_MONETARY</code><a class="headerlink" href="#locale.LC_MONETARY" title="Permalink to this definition">¶</a></dt> <dd><p>Locale category for formatting of monetary values. The available options are available from the <a class="reference internal" href="#locale.localeconv" title="locale.localeconv"><code class="xref py py-func docutils literal notranslate"><span class="pre">localeconv()</span></code></a> function.</p> </dd></dl> <dl class="data"> <dt id="locale.LC_MESSAGES"> <code class="descclassname">locale.</code><code class="descname">LC_MESSAGES</code><a class="headerlink" href="#locale.LC_MESSAGES" title="Permalink to this definition">¶</a></dt> <dd><p>Locale category for message display. Python currently does not support application specific locale-aware messages. Messages displayed by the operating system, like those returned by <a class="reference internal" href="os.html#os.strerror" title="os.strerror"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.strerror()</span></code></a> might be affected by this category.</p> </dd></dl> <dl class="data"> <dt id="locale.LC_NUMERIC"> <code class="descclassname">locale.</code><code class="descname">LC_NUMERIC</code><a class="headerlink" href="#locale.LC_NUMERIC" title="Permalink to this definition">¶</a></dt> <dd><p>Locale category for formatting numbers. The functions <a class="reference internal" href="#locale.format" title="locale.format"><code class="xref py py-func docutils literal notranslate"><span class="pre">format()</span></code></a>, <a class="reference internal" href="#locale.atoi" title="locale.atoi"><code class="xref py py-func docutils literal notranslate"><span class="pre">atoi()</span></code></a>, <a class="reference internal" href="#locale.atof" title="locale.atof"><code class="xref py py-func docutils literal notranslate"><span class="pre">atof()</span></code></a> and <a class="reference internal" href="#locale.str" title="locale.str"><code class="xref py py-func docutils literal notranslate"><span class="pre">str()</span></code></a> of the <a class="reference internal" href="#module-locale" title="locale: Internationalization services."><code class="xref py py-mod docutils literal notranslate"><span class="pre">locale</span></code></a> module are affected by that category. All other numeric formatting operations are not affected.</p> </dd></dl> <dl class="data"> <dt id="locale.LC_ALL"> <code class="descclassname">locale.</code><code class="descname">LC_ALL</code><a class="headerlink" href="#locale.LC_ALL" title="Permalink to this definition">¶</a></dt> <dd><p>Combination of all locale settings. If this flag is used when the locale is changed, setting the locale for all categories is attempted. If that fails for any category, no category is changed at all. When the locale is retrieved using this flag, a string indicating the setting for all categories is returned. This string can be later used to restore the settings.</p> </dd></dl> <dl class="data"> <dt id="locale.CHAR_MAX"> <code class="descclassname">locale.</code><code class="descname">CHAR_MAX</code><a class="headerlink" href="#locale.CHAR_MAX" title="Permalink to this definition">¶</a></dt> <dd><p>This is a symbolic constant used for different values returned by <a class="reference internal" href="#locale.localeconv" title="locale.localeconv"><code class="xref py py-func docutils literal notranslate"><span class="pre">localeconv()</span></code></a>.</p> </dd></dl> <p>Example:</p> <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">locale</span> <span class="gp">>>> </span><span class="n">loc</span> <span class="o">=</span> <span class="n">locale</span><span class="o">.</span><span class="n">getlocale</span><span class="p">()</span> <span class="c1"># get current locale</span> <span class="go"># use German locale; name might vary with platform</span> <span class="gp">>>> </span><span class="n">locale</span><span class="o">.</span><span class="n">setlocale</span><span class="p">(</span><span class="n">locale</span><span class="o">.</span><span class="n">LC_ALL</span><span class="p">,</span> <span class="s1">'de_DE'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">locale</span><span class="o">.</span><span class="n">strcoll</span><span class="p">(</span><span class="s1">'f</span><span class="se">\xe4</span><span class="s1">n'</span><span class="p">,</span> <span class="s1">'foo'</span><span class="p">)</span> <span class="c1"># compare a string containing an umlaut</span> <span class="gp">>>> </span><span class="n">locale</span><span class="o">.</span><span class="n">setlocale</span><span class="p">(</span><span class="n">locale</span><span class="o">.</span><span class="n">LC_ALL</span><span class="p">,</span> <span class="s1">''</span><span class="p">)</span> <span class="c1"># use user's preferred locale</span> <span class="gp">>>> </span><span class="n">locale</span><span class="o">.</span><span class="n">setlocale</span><span class="p">(</span><span class="n">locale</span><span class="o">.</span><span class="n">LC_ALL</span><span class="p">,</span> <span class="s1">'C'</span><span class="p">)</span> <span class="c1"># use default (C) locale</span> <span class="gp">>>> </span><span class="n">locale</span><span class="o">.</span><span class="n">setlocale</span><span class="p">(</span><span class="n">locale</span><span class="o">.</span><span class="n">LC_ALL</span><span class="p">,</span> <span class="n">loc</span><span class="p">)</span> <span class="c1"># restore saved locale</span> </pre></div> </div> <div class="section" id="background-details-hints-tips-and-caveats"> <h2>23.2.1. Background, details, hints, tips and caveats<a class="headerlink" href="#background-details-hints-tips-and-caveats" title="Permalink to this headline">¶</a></h2> <p>The C standard defines the locale as a program-wide property that may be relatively expensive to change. On top of that, some implementation are broken in such a way that frequent locale changes may cause core dumps. This makes the locale somewhat painful to use correctly.</p> <p>Initially, when a program is started, the locale is the <code class="docutils literal notranslate"><span class="pre">C</span></code> locale, no matter what the user’s preferred locale is. There is one exception: the <a class="reference internal" href="#locale.LC_CTYPE" title="locale.LC_CTYPE"><code class="xref py py-data docutils literal notranslate"><span class="pre">LC_CTYPE</span></code></a> category is changed at startup to set the current locale encoding to the user’s preferred locale encoding. The program must explicitly say that it wants the user’s preferred locale settings for other categories by calling <code class="docutils literal notranslate"><span class="pre">setlocale(LC_ALL,</span> <span class="pre">'')</span></code>.</p> <p>It is generally a bad idea to call <a class="reference internal" href="#locale.setlocale" title="locale.setlocale"><code class="xref py py-func docutils literal notranslate"><span class="pre">setlocale()</span></code></a> in some library routine, since as a side effect it affects the entire program. Saving and restoring it is almost as bad: it is expensive and affects other threads that happen to run before the settings have been restored.</p> <p>If, when coding a module for general use, you need a locale independent version of an operation that is affected by the locale (such as certain formats used with <a class="reference internal" href="time.html#time.strftime" title="time.strftime"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.strftime()</span></code></a>), you will have to find a way to do it without using the standard library routine. Even better is convincing yourself that using locale settings is okay. Only as a last resort should you document that your module is not compatible with non-<code class="docutils literal notranslate"><span class="pre">C</span></code> locale settings.</p> <p>The only way to perform numeric operations according to the locale is to use the special functions defined by this module: <a class="reference internal" href="#locale.atof" title="locale.atof"><code class="xref py py-func docutils literal notranslate"><span class="pre">atof()</span></code></a>, <a class="reference internal" href="#locale.atoi" title="locale.atoi"><code class="xref py py-func docutils literal notranslate"><span class="pre">atoi()</span></code></a>, <a class="reference internal" href="#locale.format" title="locale.format"><code class="xref py py-func docutils literal notranslate"><span class="pre">format()</span></code></a>, <a class="reference internal" href="#locale.str" title="locale.str"><code class="xref py py-func docutils literal notranslate"><span class="pre">str()</span></code></a>.</p> <p>There is no way to perform case conversions and character classifications according to the locale. For (Unicode) text strings these are done according to the character value only, while for byte strings, the conversions and classifications are done according to the ASCII value of the byte, and bytes whose high bit is set (i.e., non-ASCII bytes) are never converted or considered part of a character class such as letter or whitespace.</p> </div> <div class="section" id="for-extension-writers-and-programs-that-embed-python"> <span id="embedding-locale"></span><h2>23.2.2. For extension writers and programs that embed Python<a class="headerlink" href="#for-extension-writers-and-programs-that-embed-python" title="Permalink to this headline">¶</a></h2> <p>Extension modules should never call <a class="reference internal" href="#locale.setlocale" title="locale.setlocale"><code class="xref py py-func docutils literal notranslate"><span class="pre">setlocale()</span></code></a>, except to find out what the current locale is. But since the return value can only be used portably to restore it, that is not very useful (except perhaps to find out whether or not the locale is <code class="docutils literal notranslate"><span class="pre">C</span></code>).</p> <p>When Python code uses the <a class="reference internal" href="#module-locale" title="locale: Internationalization services."><code class="xref py py-mod docutils literal notranslate"><span class="pre">locale</span></code></a> module to change the locale, this also affects the embedding application. If the embedding application doesn’t want this to happen, it should remove the <code class="xref py py-mod docutils literal notranslate"><span class="pre">_locale</span></code> extension module (which does all the work) from the table of built-in modules in the <code class="file docutils literal notranslate"><span class="pre">config.c</span></code> file, and make sure that the <code class="xref py py-mod docutils literal notranslate"><span class="pre">_locale</span></code> module is not accessible as a shared library.</p> </div> <div class="section" id="access-to-message-catalogs"> <span id="locale-gettext"></span><h2>23.2.3. Access to message catalogs<a class="headerlink" href="#access-to-message-catalogs" title="Permalink to this headline">¶</a></h2> <dl class="function"> <dt id="locale.gettext"> <code class="descclassname">locale.</code><code class="descname">gettext</code><span class="sig-paren">(</span><em>msg</em><span class="sig-paren">)</span><a class="headerlink" href="#locale.gettext" title="Permalink to this definition">¶</a></dt> <dd></dd></dl> <dl class="function"> <dt id="locale.dgettext"> <code class="descclassname">locale.</code><code class="descname">dgettext</code><span class="sig-paren">(</span><em>domain</em>, <em>msg</em><span class="sig-paren">)</span><a class="headerlink" href="#locale.dgettext" title="Permalink to this definition">¶</a></dt> <dd></dd></dl> <dl class="function"> <dt id="locale.dcgettext"> <code class="descclassname">locale.</code><code class="descname">dcgettext</code><span class="sig-paren">(</span><em>domain</em>, <em>msg</em>, <em>category</em><span class="sig-paren">)</span><a class="headerlink" href="#locale.dcgettext" title="Permalink to this definition">¶</a></dt> <dd></dd></dl> <dl class="function"> <dt id="locale.textdomain"> <code class="descclassname">locale.</code><code class="descname">textdomain</code><span class="sig-paren">(</span><em>domain</em><span class="sig-paren">)</span><a class="headerlink" href="#locale.textdomain" title="Permalink to this definition">¶</a></dt> <dd></dd></dl> <dl class="function"> <dt id="locale.bindtextdomain"> <code class="descclassname">locale.</code><code class="descname">bindtextdomain</code><span class="sig-paren">(</span><em>domain</em>, <em>dir</em><span class="sig-paren">)</span><a class="headerlink" href="#locale.bindtextdomain" title="Permalink to this definition">¶</a></dt> <dd></dd></dl> <p>The locale module exposes the C library’s gettext interface on systems that provide this interface. It consists of the functions <code class="xref py py-func docutils literal notranslate"><span class="pre">gettext()</span></code>, <code class="xref py py-func docutils literal notranslate"><span class="pre">dgettext()</span></code>, <code class="xref py py-func docutils literal notranslate"><span class="pre">dcgettext()</span></code>, <code class="xref py py-func docutils literal notranslate"><span class="pre">textdomain()</span></code>, <code class="xref py py-func docutils literal notranslate"><span class="pre">bindtextdomain()</span></code>, and <code class="xref py py-func docutils literal notranslate"><span class="pre">bind_textdomain_codeset()</span></code>. These are similar to the same functions in the <a class="reference internal" href="gettext.html#module-gettext" title="gettext: Multilingual internationalization services."><code class="xref py py-mod docutils literal notranslate"><span class="pre">gettext</span></code></a> module, but use the C library’s binary format for message catalogs, and the C library’s search algorithms for locating message catalogs.</p> <p>Python applications should normally find no need to invoke these functions, and should use <a class="reference internal" href="gettext.html#module-gettext" title="gettext: Multilingual internationalization services."><code class="xref py py-mod docutils literal notranslate"><span class="pre">gettext</span></code></a> instead. A known exception to this rule are applications that link with additional C libraries which internally invoke <code class="xref c c-func docutils literal notranslate"><span class="pre">gettext()</span></code> or <code class="xref c c-func docutils literal notranslate"><span class="pre">dcgettext()</span></code>. For these applications, it may be necessary to bind the text domain, so that the libraries can properly locate their message catalogs.</p> </div> </div> </div> </div> </div> <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> <div class="sphinxsidebarwrapper"> <h3><a href="../contents.html">Table Of Contents</a></h3> <ul> <li><a class="reference internal" href="#">23.2. <code class="docutils literal notranslate"><span class="pre">locale</span></code> — Internationalization services</a><ul> <li><a class="reference internal" href="#background-details-hints-tips-and-caveats">23.2.1. Background, details, hints, tips and caveats</a></li> <li><a class="reference internal" href="#for-extension-writers-and-programs-that-embed-python">23.2.2. For extension writers and programs that embed Python</a></li> <li><a class="reference internal" href="#access-to-message-catalogs">23.2.3. Access to message catalogs</a></li> </ul> </li> </ul> <h4>Previous topic</h4> <p class="topless"><a href="gettext.html" title="previous chapter">23.1. <code class="docutils literal notranslate"><span class="pre">gettext</span></code> — Multilingual internationalization services</a></p> <h4>Next topic</h4> <p class="topless"><a href="frameworks.html" title="next chapter">24. Program Frameworks</a></p> <div role="note" aria-label="source link"> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../bugs.html">Report a Bug</a></li> <li> <a href="https://github.com/python/cpython/blob/3.6/Doc/library/locale.rst" rel="nofollow">Show Source </a> </li> </ul> </div> </div> </div> <div class="clearer"></div> </div> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="frameworks.html" title="24. Program Frameworks" >next</a> |</li> <li class="right" > <a href="gettext.html" title="23.1. gettext — Multilingual internationalization services" >previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="https://www.python.org/">Python</a> »</li> <li> <a href="../index.html">3.6.7 Documentation</a> » </li> <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li> <li class="nav-item nav-item-2"><a href="i18n.html" >23. Internationalization</a> »</li> <li class="right"> <div class="inline-search" style="display: none" role="search"> <form class="inline-search" action="../search.html" method="get"> <input placeholder="Quick search" type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </div> <script type="text/javascript">$('.inline-search').show(0);</script> | </li> </ul> </div> <div class="footer"> © <a href="../copyright.html">Copyright</a> 2001-2023, Python Software Foundation. <br /> The Python Software Foundation is a non-profit corporation. <a href="https://www.python.org/psf/donations/">Please donate.</a> <br /> Last updated on Dec 18, 2023. <a href="../bugs.html">Found a bug</a>? <br /> Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.7.6. </div> </body> </html>
Save
cmd:
run