summaryrefslogtreecommitdiff
path: root/devdocs/python~3.12/library%2Flocale.html
diff options
context:
space:
mode:
Diffstat (limited to 'devdocs/python~3.12/library%2Flocale.html')
-rw-r--r--devdocs/python~3.12/library%2Flocale.html187
1 files changed, 187 insertions, 0 deletions
diff --git a/devdocs/python~3.12/library%2Flocale.html b/devdocs/python~3.12/library%2Flocale.html
new file mode 100644
index 00000000..23ec19e5
--- /dev/null
+++ b/devdocs/python~3.12/library%2Flocale.html
@@ -0,0 +1,187 @@
+ <span id="locale-internationalization-services"></span><h1>locale — Internationalization services</h1> <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/locale.py">Lib/locale.py</a></p> <p>The <a class="reference internal" href="#module-locale" title="locale: Internationalization services."><code>locale</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>locale</code></a> module is implemented on top of the <code>_locale</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>locale</code></a> module defines the following exception and functions:</p> <dl class="py exception"> <dt class="sig sig-object py" id="locale.Error">
+<code>exception locale.Error</code> </dt> <dd>
+<p>Exception raised when the locale passed to <a class="reference internal" href="#locale.setlocale" title="locale.setlocale"><code>setlocale()</code></a> is not recognized.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="locale.setlocale">
+<code>locale.setlocale(category, locale=None)</code> </dt> <dd>
+<p>If <em>locale</em> is given and not <code>None</code>, <a class="reference internal" href="#locale.setlocale" title="locale.setlocale"><code>setlocale()</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>Error</code></a> is raised. If successful, the new locale setting is returned.</p> <p>If <em>locale</em> is omitted or <code>None</code>, the current setting for <em>category</em> is returned.</p> <p><a class="reference internal" href="#locale.setlocale" title="locale.setlocale"><code>setlocale()</code></a> is not thread-safe on most systems. Applications typically start with a call of</p> <pre data-language="python">import locale
+locale.setlocale(locale.LC_ALL, '')
+</pre> <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>LANG</code> environment variable). If the locale is not changed thereafter, using multithreading should not cause problems.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="locale.localeconv">
+<code>locale.localeconv()</code> </dt> <dd>
+<p>Returns the database of the local conventions as a dictionary. This dictionary has the following strings as keys:</p> <table class="docutils align-default"> <thead> <tr>
+<th class="head"><p>Category</p></th> <th class="head"><p>Key</p></th> <th class="head"><p>Meaning</p></th> </tr> </thead> <tr>
+<td><p><a class="reference internal" href="#locale.LC_NUMERIC" title="locale.LC_NUMERIC"><code>LC_NUMERIC</code></a></p></td> <td><p><code>'decimal_point'</code></p></td> <td><p>Decimal point character.</p></td> </tr> <tr>
+<td></td> <td><p><code>'grouping'</code></p></td> <td><p>Sequence of numbers specifying which relative positions the <code>'thousands_sep'</code> is expected. If the sequence is terminated with <a class="reference internal" href="#locale.CHAR_MAX" title="locale.CHAR_MAX"><code>CHAR_MAX</code></a>, no further grouping is performed. If the sequence terminates with a <code>0</code>, the last group size is repeatedly used.</p></td> </tr> <tr>
+<td></td> <td><p><code>'thousands_sep'</code></p></td> <td><p>Character used between groups.</p></td> </tr> <tr>
+<td><p><a class="reference internal" href="#locale.LC_MONETARY" title="locale.LC_MONETARY"><code>LC_MONETARY</code></a></p></td> <td><p><code>'int_curr_symbol'</code></p></td> <td><p>International currency symbol.</p></td> </tr> <tr>
+<td></td> <td><p><code>'currency_symbol'</code></p></td> <td><p>Local currency symbol.</p></td> </tr> <tr>
+<td></td> <td><p><code>'p_cs_precedes/n_cs_precedes'</code></p></td> <td><p>Whether the currency symbol precedes the value (for positive resp. negative values).</p></td> </tr> <tr>
+<td></td> <td><p><code>'p_sep_by_space/n_sep_by_space'</code></p></td> <td><p>Whether the currency symbol is separated from the value by a space (for positive resp. negative values).</p></td> </tr> <tr>
+<td></td> <td><p><code>'mon_decimal_point'</code></p></td> <td><p>Decimal point used for monetary values.</p></td> </tr> <tr>
+<td></td> <td><p><code>'frac_digits'</code></p></td> <td><p>Number of fractional digits used in local formatting of monetary values.</p></td> </tr> <tr>
+<td></td> <td><p><code>'int_frac_digits'</code></p></td> <td><p>Number of fractional digits used in international formatting of monetary values.</p></td> </tr> <tr>
+<td></td> <td><p><code>'mon_thousands_sep'</code></p></td> <td><p>Group separator used for monetary values.</p></td> </tr> <tr>
+<td></td> <td><p><code>'mon_grouping'</code></p></td> <td><p>Equivalent to <code>'grouping'</code>, used for monetary values.</p></td> </tr> <tr>
+<td></td> <td><p><code>'positive_sign'</code></p></td> <td><p>Symbol used to annotate a positive monetary value.</p></td> </tr> <tr>
+<td></td> <td><p><code>'negative_sign'</code></p></td> <td><p>Symbol used to annotate a negative monetary value.</p></td> </tr> <tr>
+<td></td> <td><p><code>'p_sign_posn/n_sign_posn'</code></p></td> <td><p>The position of the sign (for positive resp. negative values), see below.</p></td> </tr> </table> <p>All numeric values can be set to <a class="reference internal" href="#locale.CHAR_MAX" title="locale.CHAR_MAX"><code>CHAR_MAX</code></a> to indicate that there is no value specified in this locale.</p> <p>The possible values for <code>'p_sign_posn'</code> and <code>'n_sign_posn'</code> are given below.</p> <table class="docutils align-default"> <thead> <tr>
+<th class="head"><p>Value</p></th> <th class="head"><p>Explanation</p></th> </tr> </thead> <tr>
+<td><p><code>0</code></p></td> <td><p>Currency and value are surrounded by parentheses.</p></td> </tr> <tr>
+<td><p><code>1</code></p></td> <td><p>The sign should precede the value and currency symbol.</p></td> </tr> <tr>
+<td><p><code>2</code></p></td> <td><p>The sign should follow the value and currency symbol.</p></td> </tr> <tr>
+<td><p><code>3</code></p></td> <td><p>The sign should immediately precede the value.</p></td> </tr> <tr>
+<td><p><code>4</code></p></td> <td><p>The sign should immediately follow the value.</p></td> </tr> <tr>
+<td><p><code>CHAR_MAX</code></p></td> <td><p>Nothing is specified in this locale.</p></td> </tr> </table> <p>The function temporarily sets the <code>LC_CTYPE</code> locale to the <code>LC_NUMERIC</code> locale or the <code>LC_MONETARY</code> locale if locales are different and numeric or monetary strings are non-ASCII. This temporary change affects other threads.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.7: </span>The function now temporarily sets the <code>LC_CTYPE</code> locale to the <code>LC_NUMERIC</code> locale in some cases.</p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="locale.nl_langinfo">
+<code>locale.nl_langinfo(option)</code> </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>nl_langinfo()</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="py data"> <dt class="sig sig-object py" id="locale.CODESET">
+<code>locale.CODESET</code> </dt> <dd>
+<p>Get a string with the name of the character encoding used in the selected locale.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="locale.D_T_FMT">
+<code>locale.D_T_FMT</code> </dt> <dd>
+<p>Get a string that can be used as a format string for <a class="reference internal" href="time#time.strftime" title="time.strftime"><code>time.strftime()</code></a> to represent date and time in a locale-specific way.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="locale.D_FMT">
+<code>locale.D_FMT</code> </dt> <dd>
+<p>Get a string that can be used as a format string for <a class="reference internal" href="time#time.strftime" title="time.strftime"><code>time.strftime()</code></a> to represent a date in a locale-specific way.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="locale.T_FMT">
+<code>locale.T_FMT</code> </dt> <dd>
+<p>Get a string that can be used as a format string for <a class="reference internal" href="time#time.strftime" title="time.strftime"><code>time.strftime()</code></a> to represent a time in a locale-specific way.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="locale.T_FMT_AMPM">
+<code>locale.T_FMT_AMPM</code> </dt> <dd>
+<p>Get a format string for <a class="reference internal" href="time#time.strftime" title="time.strftime"><code>time.strftime()</code></a> to represent time in the am/pm format.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py"> <span class="sig-name descname">DAY_1 ... DAY_7</span>
+</dt> <dd>
+<p>Get the name of the n-th day of the week.</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p>This follows the US convention of <code>DAY_1</code> being Sunday, not the international convention (ISO 8601) that Monday is the first day of the week.</p> </div> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py"> <span class="sig-name descname">ABDAY_1 ... ABDAY_7</span>
+</dt> <dd>
+<p>Get the abbreviated name of the n-th day of the week.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py"> <span class="sig-name descname">MON_1 ... MON_12</span>
+</dt> <dd>
+<p>Get the name of the n-th month.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py"> <span class="sig-name descname">ABMON_1 ... ABMON_12</span>
+</dt> <dd>
+<p>Get the abbreviated name of the n-th month.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="locale.RADIXCHAR">
+<code>locale.RADIXCHAR</code> </dt> <dd>
+<p>Get the radix character (decimal dot, decimal comma, etc.).</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="locale.THOUSEP">
+<code>locale.THOUSEP</code> </dt> <dd>
+<p>Get the separator character for thousands (groups of three digits).</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="locale.YESEXPR">
+<code>locale.YESEXPR</code> </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> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="locale.NOEXPR">
+<code>locale.NOEXPR</code> </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> <div class="admonition note"> <p class="admonition-title">Note</p> <p>The regular expressions for <a class="reference internal" href="#locale.YESEXPR" title="locale.YESEXPR"><code>YESEXPR</code></a> and <a class="reference internal" href="#locale.NOEXPR" title="locale.NOEXPR"><code>NOEXPR</code></a> use syntax suitable for the <code>regex()</code> function from the C library, which might differ from the syntax used in <a class="reference internal" href="re#module-re" title="re: Regular expression operations."><code>re</code></a>.</p> </div> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="locale.CRNCYSTR">
+<code>locale.CRNCYSTR</code> </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="py data"> <dt class="sig sig-object py" id="locale.ERA">
+<code>locale.ERA</code> </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>E</code> modifier in their format strings causes the <a class="reference internal" href="time#time.strftime" title="time.strftime"><code>time.strftime()</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="py data"> <dt class="sig sig-object py" id="locale.ERA_D_T_FMT">
+<code>locale.ERA_D_T_FMT</code> </dt> <dd>
+<p>Get a format string for <a class="reference internal" href="time#time.strftime" title="time.strftime"><code>time.strftime()</code></a> to represent date and time in a locale-specific era-based way.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="locale.ERA_D_FMT">
+<code>locale.ERA_D_FMT</code> </dt> <dd>
+<p>Get a format string for <a class="reference internal" href="time#time.strftime" title="time.strftime"><code>time.strftime()</code></a> to represent a date in a locale-specific era-based way.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="locale.ERA_T_FMT">
+<code>locale.ERA_T_FMT</code> </dt> <dd>
+<p>Get a format string for <a class="reference internal" href="time#time.strftime" title="time.strftime"><code>time.strftime()</code></a> to represent a time in a locale-specific era-based way.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="locale.ALT_DIGITS">
+<code>locale.ALT_DIGITS</code> </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="py function"> <dt class="sig sig-object py" id="locale.getdefaultlocale">
+<code>locale.getdefaultlocale([envvars])</code> </dt> <dd>
+<p>Tries to determine the default locale settings and returns them as a tuple of the form <code>(language code, encoding)</code>.</p> <p>According to POSIX, a program which has not called <code>setlocale(LC_ALL, '')</code> runs using the portable <code>'C'</code> locale. Calling <code>setlocale(LC_ALL, '')</code> lets it use the default locale as defined by the <span class="target" id="index-2"></span><code>LANG</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>LANG</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>'LANG'</code>. The GNU gettext search path contains <code>'LC_ALL'</code>, <code>'LC_CTYPE'</code>, <code>'LANG'</code> and <code>'LANGUAGE'</code>, in that order.</p> <p>Except for the code <code>'C'</code>, the language code corresponds to <span class="target" id="index-4"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc1766.html"><strong>RFC 1766</strong></a>. <em>language code</em> and <em>encoding</em> may be <code>None</code> if their values cannot be determined.</p> <div class="deprecated-removed"> <p><span class="versionmodified">Deprecated since version 3.11, will be removed in version 3.15.</span></p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="locale.getlocale">
+<code>locale.getlocale(category=LC_CTYPE)</code> </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>LC_*</code> values except <a class="reference internal" href="#locale.LC_ALL" title="locale.LC_ALL"><code>LC_ALL</code></a>. It defaults to <a class="reference internal" href="#locale.LC_CTYPE" title="locale.LC_CTYPE"><code>LC_CTYPE</code></a>.</p> <p>Except for the code <code>'C'</code>, the language code corresponds to <span class="target" id="index-5"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc1766.html"><strong>RFC 1766</strong></a>. <em>language code</em> and <em>encoding</em> may be <code>None</code> if their values cannot be determined.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="locale.getpreferredencoding">
+<code>locale.getpreferredencoding(do_setlocale=True)</code> </dt> <dd>
+<p>Return the <a class="reference internal" href="../glossary#term-locale-encoding"><span class="xref std std-term">locale encoding</span></a> 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>setlocale()</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>False</code>.</p> <p>On Android or if the <a class="reference internal" href="os#utf8-mode"><span class="std std-ref">Python UTF-8 Mode</span></a> is enabled, always return <code>'utf-8'</code>, the <a class="reference internal" href="../glossary#term-locale-encoding"><span class="xref std std-term">locale encoding</span></a> and the <em>do_setlocale</em> argument are ignored.</p> <p>The <a class="reference internal" href="../c-api/init_config#c-preinit"><span class="std std-ref">Python preinitialization</span></a> configures the LC_CTYPE locale. See also the <a class="reference internal" href="../glossary#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">filesystem encoding and error handler</span></a>.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.7: </span>The function now always returns <code>"utf-8"</code> on Android or if the <a class="reference internal" href="os#utf8-mode"><span class="std std-ref">Python UTF-8 Mode</span></a> is enabled.</p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="locale.getencoding">
+<code>locale.getencoding()</code> </dt> <dd>
+<p>Get the current <a class="reference internal" href="../glossary#term-locale-encoding"><span class="xref std std-term">locale encoding</span></a>:</p> <ul class="simple"> <li>On Android and VxWorks, return <code>"utf-8"</code>.</li> <li>On Unix, return the encoding of the current <a class="reference internal" href="#locale.LC_CTYPE" title="locale.LC_CTYPE"><code>LC_CTYPE</code></a> locale. Return <code>"utf-8"</code> if <code>nl_langinfo(CODESET)</code> returns an empty string: for example, if the current LC_CTYPE locale is not supported.</li> <li>On Windows, return the ANSI code page.</li> </ul> <p>The <a class="reference internal" href="../c-api/init_config#c-preinit"><span class="std std-ref">Python preinitialization</span></a> configures the LC_CTYPE locale. See also the <a class="reference internal" href="../glossary#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">filesystem encoding and error handler</span></a>.</p> <p>This function is similar to <a class="reference internal" href="#locale.getpreferredencoding" title="locale.getpreferredencoding"><code>getpreferredencoding(False)</code></a> except this function ignores the <a class="reference internal" href="os#utf8-mode"><span class="std std-ref">Python UTF-8 Mode</span></a>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.11.</span></p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="locale.normalize">
+<code>locale.normalize(localename)</code> </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>setlocale()</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>setlocale()</code></a>.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="locale.resetlocale">
+<code>locale.resetlocale(category=LC_ALL)</code> </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>getdefaultlocale()</code></a>. <em>category</em> defaults to <a class="reference internal" href="#locale.LC_ALL" title="locale.LC_ALL"><code>LC_ALL</code></a>.</p> <div class="deprecated-removed"> <p><span class="versionmodified">Deprecated since version 3.11, will be removed in version 3.13.</span></p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="locale.strcoll">
+<code>locale.strcoll(string1, string2)</code> </dt> <dd>
+<p>Compares two strings according to the current <a class="reference internal" href="#locale.LC_COLLATE" title="locale.LC_COLLATE"><code>LC_COLLATE</code></a> setting. As any other compare function, returns a negative, or a positive value, or <code>0</code>, depending on whether <em>string1</em> collates before or after <em>string2</em> or is equal to it.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="locale.strxfrm">
+<code>locale.strxfrm(string)</code> </dt> <dd>
+<p>Transforms a string to one that can be used in locale-aware comparisons. For example, <code>strxfrm(s1) &lt; strxfrm(s2)</code> is equivalent to <code>strcoll(s1, s2) &lt; 0</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="py function"> <dt class="sig sig-object py" id="locale.format_string">
+<code>locale.format_string(format, val, grouping=False, monetary=False)</code> </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>LC_NUMERIC</code></a> setting. The format follows the conventions of the <code>%</code> operator. For floating point values, the decimal point is modified if appropriate. If <em>grouping</em> is <code>True</code>, 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>Processes formatting specifiers as in <code>format % val</code>, but takes the current locale settings into account.</p> <div class="versionchanged"> <p><span class="versionmodified changed">Changed in version 3.7: </span>The <em>monetary</em> keyword parameter was added.</p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="locale.currency">
+<code>locale.currency(val, symbol=True, grouping=False, international=False)</code> </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>LC_MONETARY</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 <code>True</code> (which is not the default), grouping is done with the value. If <em>international</em> is <code>True</code> (which is not the default), the international currency symbol is used.</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p>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>setlocale()</code></a> first.</p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="locale.str">
+<code>locale.str(float)</code> </dt> <dd>
+<p>Formats a floating point number using the same format as the built-in function <code>str(float)</code>, but takes the decimal point into account.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="locale.delocalize">
+<code>locale.delocalize(string)</code> </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>LC_NUMERIC</code></a> settings.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.5.</span></p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="locale.localize">
+<code>locale.localize(string, grouping=False, monetary=False)</code> </dt> <dd>
+<p>Converts a normalized number string into a formatted string following the <a class="reference internal" href="#locale.LC_NUMERIC" title="locale.LC_NUMERIC"><code>LC_NUMERIC</code></a> settings.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.10.</span></p> </div> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="locale.atof">
+<code>locale.atof(string, func=float)</code> </dt> <dd>
+<p>Converts a string to a number, following the <a class="reference internal" href="#locale.LC_NUMERIC" title="locale.LC_NUMERIC"><code>LC_NUMERIC</code></a> settings, by calling <em>func</em> on the result of calling <a class="reference internal" href="#locale.delocalize" title="locale.delocalize"><code>delocalize()</code></a> on <em>string</em>.</p> </dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="locale.atoi">
+<code>locale.atoi(string)</code> </dt> <dd>
+<p>Converts a string to an integer, following the <a class="reference internal" href="#locale.LC_NUMERIC" title="locale.LC_NUMERIC"><code>LC_NUMERIC</code></a> conventions.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="locale.LC_CTYPE">
+<code>locale.LC_CTYPE</code> </dt> <dd>
+<p>Locale category for the character type functions. Most importantly, this category defines the text encoding, i.e. how bytes are interpreted as Unicode codepoints. See <span class="target" id="index-6"></span><a class="pep reference external" href="https://peps.python.org/pep-0538/"><strong>PEP 538</strong></a> and <span class="target" id="index-7"></span><a class="pep reference external" href="https://peps.python.org/pep-0540/"><strong>PEP 540</strong></a> for how this variable might be automatically coerced to <code>C.UTF-8</code> to avoid issues created by invalid settings in containers or incompatible settings passed over remote SSH connections.</p> <p>Python doesn’t internally use locale-dependent character transformation functions from <code>ctype.h</code>. Instead, an internal <code>pyctype.h</code> provides locale-independent equivalents like <code>Py_TOLOWER</code>.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="locale.LC_COLLATE">
+<code>locale.LC_COLLATE</code> </dt> <dd>
+<p>Locale category for sorting strings. The functions <a class="reference internal" href="#locale.strcoll" title="locale.strcoll"><code>strcoll()</code></a> and <a class="reference internal" href="#locale.strxfrm" title="locale.strxfrm"><code>strxfrm()</code></a> of the <a class="reference internal" href="#module-locale" title="locale: Internationalization services."><code>locale</code></a> module are affected.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="locale.LC_TIME">
+<code>locale.LC_TIME</code> </dt> <dd>
+<p>Locale category for the formatting of time. The function <a class="reference internal" href="time#time.strftime" title="time.strftime"><code>time.strftime()</code></a> follows these conventions.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="locale.LC_MONETARY">
+<code>locale.LC_MONETARY</code> </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>localeconv()</code></a> function.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="locale.LC_MESSAGES">
+<code>locale.LC_MESSAGES</code> </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#os.strerror" title="os.strerror"><code>os.strerror()</code></a> might be affected by this category.</p> <p>This value may not be available on operating systems not conforming to the POSIX standard, most notably Windows.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="locale.LC_NUMERIC">
+<code>locale.LC_NUMERIC</code> </dt> <dd>
+<p>Locale category for formatting numbers. The functions <a class="reference internal" href="#locale.format_string" title="locale.format_string"><code>format_string()</code></a>, <a class="reference internal" href="#locale.atoi" title="locale.atoi"><code>atoi()</code></a>, <a class="reference internal" href="#locale.atof" title="locale.atof"><code>atof()</code></a> and <a class="reference internal" href="#locale.str" title="locale.str"><code>str()</code></a> of the <a class="reference internal" href="#module-locale" title="locale: Internationalization services."><code>locale</code></a> module are affected by that category. All other numeric formatting operations are not affected.</p> </dd>
+</dl> <dl class="py data"> <dt class="sig sig-object py" id="locale.LC_ALL">
+<code>locale.LC_ALL</code> </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="py data"> <dt class="sig sig-object py" id="locale.CHAR_MAX">
+<code>locale.CHAR_MAX</code> </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>localeconv()</code></a>.</p> </dd>
+</dl> <p>Example:</p> <pre data-language="python">&gt;&gt;&gt; import locale
+&gt;&gt;&gt; loc = locale.getlocale() # get current locale
+# use German locale; name might vary with platform
+&gt;&gt;&gt; locale.setlocale(locale.LC_ALL, 'de_DE')
+&gt;&gt;&gt; locale.strcoll('f\xe4n', 'foo') # compare a string containing an umlaut
+&gt;&gt;&gt; locale.setlocale(locale.LC_ALL, '') # use user's preferred locale
+&gt;&gt;&gt; locale.setlocale(locale.LC_ALL, 'C') # use default (C) locale
+&gt;&gt;&gt; locale.setlocale(locale.LC_ALL, loc) # restore saved locale
+</pre> <section id="background-details-hints-tips-and-caveats"> <h2>Background, details, hints, tips and caveats</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 implementations 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>C</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>LC_CTYPE</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>setlocale(LC_ALL, '')</code>.</p> <p>It is generally a bad idea to call <a class="reference internal" href="#locale.setlocale" title="locale.setlocale"><code>setlocale()</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#time.strftime" title="time.strftime"><code>time.strftime()</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>C</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>atof()</code></a>, <a class="reference internal" href="#locale.atoi" title="locale.atoi"><code>atoi()</code></a>, <a class="reference internal" href="#locale.format_string" title="locale.format_string"><code>format_string()</code></a>, <a class="reference internal" href="#locale.str" title="locale.str"><code>str()</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> </section> <section id="for-extension-writers-and-programs-that-embed-python"> <span id="embedding-locale"></span><h2>For extension writers and programs that embed Python</h2> <p>Extension modules should never call <a class="reference internal" href="#locale.setlocale" title="locale.setlocale"><code>setlocale()</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>C</code>).</p> <p>When Python code uses the <a class="reference internal" href="#module-locale" title="locale: Internationalization services."><code>locale</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>_locale</code> extension module (which does all the work) from the table of built-in modules in the <code>config.c</code> file, and make sure that the <code>_locale</code> module is not accessible as a shared library.</p> </section> <section id="access-to-message-catalogs"> <span id="locale-gettext"></span><h2>Access to message catalogs</h2> <dl class="py function"> <dt class="sig sig-object py" id="locale.gettext">
+<code>locale.gettext(msg)</code> </dt> <dd></dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="locale.dgettext">
+<code>locale.dgettext(domain, msg)</code> </dt> <dd></dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="locale.dcgettext">
+<code>locale.dcgettext(domain, msg, category)</code> </dt> <dd></dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="locale.textdomain">
+<code>locale.textdomain(domain)</code> </dt> <dd></dd>
+</dl> <dl class="py function"> <dt class="sig sig-object py" id="locale.bindtextdomain">
+<code>locale.bindtextdomain(domain, dir)</code> </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>gettext()</code>, <code>dgettext()</code>, <code>dcgettext()</code>, <code>textdomain()</code>, <code>bindtextdomain()</code>, and <code>bind_textdomain_codeset()</code>. These are similar to the same functions in the <a class="reference internal" href="gettext#module-gettext" title="gettext: Multilingual internationalization services."><code>gettext</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#module-gettext" title="gettext: Multilingual internationalization services."><code>gettext</code></a> instead. A known exception to this rule are applications that link with additional C libraries which internally invoke <code>gettext()</code> or <code>dcgettext()</code>. For these applications, it may be necessary to bind the text domain, so that the libraries can properly locate their message catalogs.</p> </section> <div class="_attribution">
+ <p class="_attribution-p">
+ &copy; 2001&ndash;2023 Python Software Foundation<br>Licensed under the PSF License.<br>
+ <a href="https://docs.python.org/3.12/library/locale.html" class="_attribution-link">https://docs.python.org/3.12/library/locale.html</a>
+ </p>
+</div>