Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="lib.html" title='Python Library Reference' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="next" href="module-gettext.html" /> | |
13 | <link rel="prev" href="module-shutil.html" /> | |
14 | <link rel="parent" href="allos.html" /> | |
15 | <link rel="next" href="node323.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>6.27 locale -- Internationalization services</title> | |
18 | </head> | |
19 | <body> | |
20 | <DIV CLASS="navigation"> | |
21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
23 | <tr> | |
24 | <td class='online-navigation'><a rel="prev" title="6.26.1 Example" | |
25 | href="shutil-example.html"><img src='../icons/previous.png' | |
26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
27 | <td class='online-navigation'><a rel="parent" title="6. Generic Operating System" | |
28 | href="allos.html"><img src='../icons/up.png' | |
29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
30 | <td class='online-navigation'><a rel="next" title="6.27.1 Background, details, hints," | |
31 | href="node323.html"><img src='../icons/next.png' | |
32 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
33 | <td align="center" width="100%">Python Library Reference</td> | |
34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
35 | href="contents.html"><img src='../icons/contents.png' | |
36 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
38 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
39 | <td class='online-navigation'><a rel="index" title="Index" | |
40 | href="genindex.html"><img src='../icons/index.png' | |
41 | border='0' height='32' alt='Index' width='32' /></A></td> | |
42 | </tr></table> | |
43 | <div class='online-navigation'> | |
44 | <b class="navlabel">Previous:</b> | |
45 | <a class="sectref" rel="prev" href="shutil-example.html">6.26.1 Example</A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="allos.html">6. Generic Operating System</A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="node323.html">6.27.1 Background, details, hints,</A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H1><A NAME="SECTION0082700000000000000000"> | |
56 | 6.27 <tt class="module">locale</tt> -- | |
57 | Internationalization services</A> | |
58 | </H1> | |
59 | ||
60 | <P> | |
61 | <A NAME="module-locale"></A> | |
62 | ||
63 | <P> | |
64 | The <tt class="module">locale</tt> module opens access to the POSIX locale | |
65 | database and functionality. The POSIX locale mechanism allows | |
66 | programmers to deal with certain cultural issues in an application, | |
67 | without requiring the programmer to know all the specifics of each | |
68 | country where the software is executed. | |
69 | ||
70 | <P> | |
71 | The <tt class="module">locale</tt> module is implemented on top of the | |
72 | <tt class="module">_locale</tt><a id='l2h-2405' xml:id='l2h-2405'></a> module, which in turn uses an | |
73 | ANSI C locale implementation if available. | |
74 | ||
75 | <P> | |
76 | The <tt class="module">locale</tt> module defines the following exception and | |
77 | functions: | |
78 | ||
79 | <P> | |
80 | <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-2362' xml:id='l2h-2362' class="exception">Error</tt></b></dt> | |
81 | <dd> | |
82 | Exception raised when <tt class="function">setlocale()</tt> fails. | |
83 | </dd></dl> | |
84 | ||
85 | <P> | |
86 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
87 | <td><nobr><b><tt id='l2h-2363' xml:id='l2h-2363' class="function">setlocale</tt></b>(</nobr></td> | |
88 | <td><var>category</var><big>[</big><var>, locale</var><big>]</big><var></var>)</td></tr></table></dt> | |
89 | <dd> | |
90 | If <var>locale</var> is specified, it may be a string, a tuple of the | |
91 | form <code>(<var>language code</var>, <var>encoding</var>)</code>, or <code>None</code>. | |
92 | If it is a tuple, it is converted to a string using the locale | |
93 | aliasing engine. If <var>locale</var> is given and not <code>None</code>, | |
94 | <tt class="function">setlocale()</tt> modifies the locale setting for the | |
95 | <var>category</var>. The available categories are listed in the data | |
96 | description below. The value is the name of a locale. An empty | |
97 | string specifies the user's default settings. If the modification of | |
98 | the locale fails, the exception <tt class="exception">Error</tt> is raised. If | |
99 | successful, the new locale setting is returned. | |
100 | ||
101 | <P> | |
102 | If <var>locale</var> is omitted or <code>None</code>, the current setting for | |
103 | <var>category</var> is returned. | |
104 | ||
105 | <P> | |
106 | <tt class="function">setlocale()</tt> is not thread safe on most systems. | |
107 | Applications typically start with a call of | |
108 | ||
109 | <P> | |
110 | <div class="verbatim"><pre> | |
111 | import locale | |
112 | locale.setlocale(locale.LC_ALL, '') | |
113 | </pre></div> | |
114 | ||
115 | <P> | |
116 | This sets the locale for all categories to the user's default | |
117 | setting (typically specified in the <a class="envvar" id='l2h-2406' xml:id='l2h-2406'>LANG</a> environment | |
118 | variable). If the locale is not changed thereafter, using | |
119 | multithreading should not cause problems. | |
120 | ||
121 | <P> | |
122 | ||
123 | <span class="versionnote">Changed in version 2.0: | |
124 | Added support for tuple values of the <var>locale</var> | |
125 | parameter.</span> | |
126 | ||
127 | </dl> | |
128 | ||
129 | <P> | |
130 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
131 | <td><nobr><b><tt id='l2h-2364' xml:id='l2h-2364' class="function">localeconv</tt></b>(</nobr></td> | |
132 | <td><var></var>)</td></tr></table></dt> | |
133 | <dd> | |
134 | Returns the database of the local conventions as a dictionary. | |
135 | This dictionary has the following strings as keys: | |
136 | ||
137 | <P> | |
138 | <div class="center"><table class="realtable"> | |
139 | <thead> | |
140 | <tr> | |
141 | <th class="left" >Key</th> | |
142 | <th class="left" >Category</th> | |
143 | <th class="left" >Meaning</th> | |
144 | </tr> | |
145 | </thead> | |
146 | <tbody> | |
147 | <tr><td class="left" valign="baseline"><code>LC_NUMERIC</code></td> | |
148 | <td class="left" ><code>'decimal_point'</code></td> | |
149 | <td class="left" >Decimal point character.</td></tr> | |
150 | <tr><td class="left" valign="baseline"><code></code></td> | |
151 | <td class="left" ><code>'grouping'</code></td> | |
152 | <td class="left" >Sequence of numbers specifying which relative positions | |
153 | the <code>'thousands_sep'</code> is expected. If the sequence is | |
154 | terminated with <tt class="constant">CHAR_MAX</tt>, no further grouping | |
155 | is performed. If the sequence terminates with a <code>0</code>, | |
156 | the last group size is repeatedly used.</td></tr> | |
157 | <tr><td class="left" valign="baseline"><code></code></td> | |
158 | <td class="left" ><code>'thousands_sep'</code></td> | |
159 | <td class="left" >Character used between groups.</td></tr> | |
160 | <tr><td class="left" valign="baseline"><code>LC_MONETARY</code></td> | |
161 | <td class="left" ><code>'int_curr_symbol'</code></td> | |
162 | <td class="left" >International currency symbol.</td></tr> | |
163 | <tr><td class="left" valign="baseline"><code></code></td> | |
164 | <td class="left" ><code>'currency_symbol'</code></td> | |
165 | <td class="left" >Local currency symbol.</td></tr> | |
166 | <tr><td class="left" valign="baseline"><code></code></td> | |
167 | <td class="left" ><code>'mon_decimal_point'</code></td> | |
168 | <td class="left" >Decimal point used for monetary values.</td></tr> | |
169 | <tr><td class="left" valign="baseline"><code></code></td> | |
170 | <td class="left" ><code>'mon_thousands_sep'</code></td> | |
171 | <td class="left" >Group separator used for monetary values.</td></tr> | |
172 | <tr><td class="left" valign="baseline"><code></code></td> | |
173 | <td class="left" ><code>'mon_grouping'</code></td> | |
174 | <td class="left" >Equivalent to <code>'grouping'</code>, used for monetary | |
175 | values.</td></tr> | |
176 | <tr><td class="left" valign="baseline"><code></code></td> | |
177 | <td class="left" ><code>'positive_sign'</code></td> | |
178 | <td class="left" >Symbol used to annotate a positive monetary value.</td></tr> | |
179 | <tr><td class="left" valign="baseline"><code></code></td> | |
180 | <td class="left" ><code>'negative_sign'</code></td> | |
181 | <td class="left" >Symbol used to annotate a negative monetary value.</td></tr> | |
182 | <tr><td class="left" valign="baseline"><code></code></td> | |
183 | <td class="left" ><code>'frac_digits'</code></td> | |
184 | <td class="left" >Number of fractional digits used in local formatting | |
185 | of monetary values.</td></tr> | |
186 | <tr><td class="left" valign="baseline"><code></code></td> | |
187 | <td class="left" ><code>'int_frac_digits'</code></td> | |
188 | <td class="left" >Number of fractional digits used in international | |
189 | formatting of monetary values.</td></tr></tbody> | |
190 | </table></div> | |
191 | ||
192 | <P> | |
193 | The possible values for <code>'p_sign_posn'</code> and | |
194 | <code>'n_sign_posn'</code> are given below. | |
195 | ||
196 | <P> | |
197 | <div class="center"><table class="realtable"> | |
198 | <thead> | |
199 | <tr> | |
200 | <th class="center">Value</th> | |
201 | <th class="left" >Explanation</th> | |
202 | </tr> | |
203 | </thead> | |
204 | <tbody> | |
205 | <tr><td class="center" valign="baseline"><code>0</code></td> | |
206 | <td class="left" >Currency and value are surrounded by parentheses.</td></tr> | |
207 | <tr><td class="center" valign="baseline"><code>1</code></td> | |
208 | <td class="left" >The sign should precede the value and currency symbol.</td></tr> | |
209 | <tr><td class="center" valign="baseline"><code>2</code></td> | |
210 | <td class="left" >The sign should follow the value and currency symbol.</td></tr> | |
211 | <tr><td class="center" valign="baseline"><code>3</code></td> | |
212 | <td class="left" >The sign should immediately precede the value.</td></tr> | |
213 | <tr><td class="center" valign="baseline"><code>4</code></td> | |
214 | <td class="left" >The sign should immediately follow the value.</td></tr> | |
215 | <tr><td class="center" valign="baseline"><code><tt class="constant">LC_MAX</tt></code></td> | |
216 | <td class="left" >Nothing is specified in this locale.</td></tr></tbody> | |
217 | </table></div> | |
218 | </dl> | |
219 | ||
220 | <P> | |
221 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
222 | <td><nobr><b><tt id='l2h-2365' xml:id='l2h-2365' class="function">nl_langinfo</tt></b>(</nobr></td> | |
223 | <td><var>option</var>)</td></tr></table></dt> | |
224 | <dd> | |
225 | ||
226 | <P> | |
227 | Return some locale-specific information as a string. This function is | |
228 | not available on all systems, and the set of possible options might | |
229 | also vary across platforms. The possible argument values are numbers, | |
230 | for which symbolic constants are available in the locale module. | |
231 | ||
232 | <P> | |
233 | </dl> | |
234 | ||
235 | <P> | |
236 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
237 | <td><nobr><b><tt id='l2h-2366' xml:id='l2h-2366' class="function">getdefaultlocale</tt></b>(</nobr></td> | |
238 | <td><var></var><big>[</big><var>envvars</var><big>]</big><var></var>)</td></tr></table></dt> | |
239 | <dd> | |
240 | Tries to determine the default locale settings and returns | |
241 | them as a tuple of the form <code>(<var>language code</var>, | |
242 | <var>encoding</var>)</code>. | |
243 | ||
244 | <P> | |
245 | According to POSIX, a program which has not called | |
246 | <code>setlocale(LC_ALL, '')</code> runs using the portable <code>'C'</code> | |
247 | locale. Calling <code>setlocale(LC_ALL, '')</code> lets it use the | |
248 | default locale as defined by the <a class="envvar" id='l2h-2407' xml:id='l2h-2407'>LANG</a> variable. Since we | |
249 | do not want to interfere with the current locale setting we thus | |
250 | emulate the behavior in the way described above. | |
251 | ||
252 | <P> | |
253 | To maintain compatibility with other platforms, not only the | |
254 | <a class="envvar" id='l2h-2408' xml:id='l2h-2408'>LANG</a> variable is tested, but a list of variables given as | |
255 | envvars parameter. The first found to be defined will be | |
256 | used. <var>envvars</var> defaults to the search path used in GNU gettext; | |
257 | it must always contain the variable name "<tt class="samp">LANG</tt>". The GNU | |
258 | gettext search path contains <code>'LANGUAGE'</code>, <code>'LC_ALL'</code>, | |
259 | <code>'LC_CTYPE'</code>, and <code>'LANG'</code>, in that order. | |
260 | ||
261 | <P> | |
262 | Except for the code <code>'C'</code>, the language code corresponds to | |
263 | <a class="rfc" id='rfcref-88839' xml:id='rfcref-88839' | |
264 | href="http://www.faqs.org/rfcs/rfc1766.html">RFC 1766</a>. <var>language code</var> and <var>encoding</var> may be | |
265 | <code>None</code> if their values cannot be determined. | |
266 | ||
267 | <span class="versionnote">New in version 2.0.</span> | |
268 | ||
269 | </dl> | |
270 | ||
271 | <P> | |
272 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
273 | <td><nobr><b><tt id='l2h-2367' xml:id='l2h-2367' class="function">getlocale</tt></b>(</nobr></td> | |
274 | <td><var></var><big>[</big><var>category</var><big>]</big><var></var>)</td></tr></table></dt> | |
275 | <dd> | |
276 | Returns the current setting for the given locale category as | |
277 | sequence containing <var>language code</var>, <var>encoding</var>. | |
278 | <var>category</var> may be one of the <tt class="constant">LC_*</tt> values except | |
279 | <tt class="constant">LC_ALL</tt>. It defaults to <tt class="constant">LC_CTYPE</tt>. | |
280 | ||
281 | <P> | |
282 | Except for the code <code>'C'</code>, the language code corresponds to | |
283 | <a class="rfc" id='rfcref-88841' xml:id='rfcref-88841' | |
284 | href="http://www.faqs.org/rfcs/rfc1766.html">RFC 1766</a>. <var>language code</var> and <var>encoding</var> may be | |
285 | <code>None</code> if their values cannot be determined. | |
286 | ||
287 | <span class="versionnote">New in version 2.0.</span> | |
288 | ||
289 | </dl> | |
290 | ||
291 | <P> | |
292 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
293 | <td><nobr><b><tt id='l2h-2368' xml:id='l2h-2368' class="function">getpreferredencoding</tt></b>(</nobr></td> | |
294 | <td><var></var><big>[</big><var>do_setlocale</var><big>]</big><var></var>)</td></tr></table></dt> | |
295 | <dd> | |
296 | Return the encoding used for text data, according to user | |
297 | preferences. User preferences are expressed differently on | |
298 | different systems, and might not be available programmatically on | |
299 | some systems, so this function only returns a guess. | |
300 | ||
301 | <P> | |
302 | On some systems, it is necessary to invoke <tt class="function">setlocale</tt> | |
303 | to obtain the user preferences, so this function is not thread-safe. | |
304 | If invoking setlocale is not necessary or desired, <var>do_setlocale</var> | |
305 | should be set to <code>False</code>. | |
306 | ||
307 | <P> | |
308 | ||
309 | <span class="versionnote">New in version 2.3.</span> | |
310 | ||
311 | </dl> | |
312 | ||
313 | <P> | |
314 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
315 | <td><nobr><b><tt id='l2h-2369' xml:id='l2h-2369' class="function">normalize</tt></b>(</nobr></td> | |
316 | <td><var>localename</var>)</td></tr></table></dt> | |
317 | <dd> | |
318 | Returns a normalized locale code for the given locale name. The | |
319 | returned locale code is formatted for use with | |
320 | <tt class="function">setlocale()</tt>. If normalization fails, the original name | |
321 | is returned unchanged. | |
322 | ||
323 | <P> | |
324 | If the given encoding is not known, the function defaults to | |
325 | the default encoding for the locale code just like | |
326 | <tt class="function">setlocale()</tt>. | |
327 | ||
328 | <span class="versionnote">New in version 2.0.</span> | |
329 | ||
330 | </dl> | |
331 | ||
332 | <P> | |
333 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
334 | <td><nobr><b><tt id='l2h-2370' xml:id='l2h-2370' class="function">resetlocale</tt></b>(</nobr></td> | |
335 | <td><var></var><big>[</big><var>category</var><big>]</big><var></var>)</td></tr></table></dt> | |
336 | <dd> | |
337 | Sets the locale for <var>category</var> to the default setting. | |
338 | ||
339 | <P> | |
340 | The default setting is determined by calling | |
341 | <tt class="function">getdefaultlocale()</tt>. <var>category</var> defaults to | |
342 | <tt class="constant">LC_ALL</tt>. | |
343 | ||
344 | <span class="versionnote">New in version 2.0.</span> | |
345 | ||
346 | </dl> | |
347 | ||
348 | <P> | |
349 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
350 | <td><nobr><b><tt id='l2h-2371' xml:id='l2h-2371' class="function">strcoll</tt></b>(</nobr></td> | |
351 | <td><var>string1, string2</var>)</td></tr></table></dt> | |
352 | <dd> | |
353 | Compares two strings according to the current | |
354 | <tt class="constant">LC_COLLATE</tt> setting. As any other compare function, | |
355 | returns a negative, or a positive value, or <code>0</code>, depending on | |
356 | whether <var>string1</var> collates before or after <var>string2</var> or is | |
357 | equal to it. | |
358 | </dl> | |
359 | ||
360 | <P> | |
361 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
362 | <td><nobr><b><tt id='l2h-2372' xml:id='l2h-2372' class="function">strxfrm</tt></b>(</nobr></td> | |
363 | <td><var>string</var>)</td></tr></table></dt> | |
364 | <dd> | |
365 | Transforms a string to one that can be used for the built-in | |
366 | function <tt class="function">cmp()</tt><a id='l2h-2373' xml:id='l2h-2373'></a>, and still returns | |
367 | locale-aware results. This function can be used when the same | |
368 | string is compared repeatedly, e.g. when collating a sequence of | |
369 | strings. | |
370 | </dl> | |
371 | ||
372 | <P> | |
373 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
374 | <td><nobr><b><tt id='l2h-2374' xml:id='l2h-2374' class="function">format</tt></b>(</nobr></td> | |
375 | <td><var>format, val</var><big>[</big><var>, grouping</var><big>]</big><var></var>)</td></tr></table></dt> | |
376 | <dd> | |
377 | Formats a number <var>val</var> according to the current | |
378 | <tt class="constant">LC_NUMERIC</tt> setting. The format follows the conventions | |
379 | of the <code>%</code> operator. For floating point values, the decimal | |
380 | point is modified if appropriate. If <var>grouping</var> is true, also | |
381 | takes the grouping into account. | |
382 | </dl> | |
383 | ||
384 | <P> | |
385 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
386 | <td><nobr><b><tt id='l2h-2375' xml:id='l2h-2375' class="function">str</tt></b>(</nobr></td> | |
387 | <td><var>float</var>)</td></tr></table></dt> | |
388 | <dd> | |
389 | Formats a floating point number using the same format as the | |
390 | built-in function <code>str(<var>float</var>)</code>, but takes the decimal | |
391 | point into account. | |
392 | </dl> | |
393 | ||
394 | <P> | |
395 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
396 | <td><nobr><b><tt id='l2h-2376' xml:id='l2h-2376' class="function">atof</tt></b>(</nobr></td> | |
397 | <td><var>string</var>)</td></tr></table></dt> | |
398 | <dd> | |
399 | Converts a string to a floating point number, following the | |
400 | <tt class="constant">LC_NUMERIC</tt> settings. | |
401 | </dl> | |
402 | ||
403 | <P> | |
404 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
405 | <td><nobr><b><tt id='l2h-2377' xml:id='l2h-2377' class="function">atoi</tt></b>(</nobr></td> | |
406 | <td><var>string</var>)</td></tr></table></dt> | |
407 | <dd> | |
408 | Converts a string to an integer, following the | |
409 | <tt class="constant">LC_NUMERIC</tt> conventions. | |
410 | </dl> | |
411 | ||
412 | <P> | |
413 | <dl><dt><b><tt id='l2h-2378' xml:id='l2h-2378'>LC_CTYPE</tt></b></dt> | |
414 | <dd> | |
415 | <a id='l2h-2409' xml:id='l2h-2409'></a> | |
416 | Locale category for the character type functions. Depending on the | |
417 | settings of this category, the functions of module | |
418 | <tt class="module"><a href="module-string.html">string</a></tt> dealing with case change their behaviour. | |
419 | </dd></dl> | |
420 | ||
421 | <P> | |
422 | <dl><dt><b><tt id='l2h-2379' xml:id='l2h-2379'>LC_COLLATE</tt></b></dt> | |
423 | <dd> | |
424 | Locale category for sorting strings. The functions | |
425 | <tt class="function">strcoll()</tt> and <tt class="function">strxfrm()</tt> of the | |
426 | <tt class="module">locale</tt> module are affected. | |
427 | </dd></dl> | |
428 | ||
429 | <P> | |
430 | <dl><dt><b><tt id='l2h-2380' xml:id='l2h-2380'>LC_TIME</tt></b></dt> | |
431 | <dd> | |
432 | Locale category for the formatting of time. The function | |
433 | <tt class="function">time.strftime()</tt> follows these conventions. | |
434 | </dd></dl> | |
435 | ||
436 | <P> | |
437 | <dl><dt><b><tt id='l2h-2381' xml:id='l2h-2381'>LC_MONETARY</tt></b></dt> | |
438 | <dd> | |
439 | Locale category for formatting of monetary values. The available | |
440 | options are available from the <tt class="function">localeconv()</tt> function. | |
441 | </dd></dl> | |
442 | ||
443 | <P> | |
444 | <dl><dt><b><tt id='l2h-2382' xml:id='l2h-2382'>LC_MESSAGES</tt></b></dt> | |
445 | <dd> | |
446 | Locale category for message display. Python currently does not | |
447 | support application specific locale-aware messages. Messages | |
448 | displayed by the operating system, like those returned by | |
449 | <tt class="function">os.strerror()</tt> might be affected by this category. | |
450 | </dd></dl> | |
451 | ||
452 | <P> | |
453 | <dl><dt><b><tt id='l2h-2383' xml:id='l2h-2383'>LC_NUMERIC</tt></b></dt> | |
454 | <dd> | |
455 | Locale category for formatting numbers. The functions | |
456 | <tt class="function">format()</tt>, <tt class="function">atoi()</tt>, <tt class="function">atof()</tt> and | |
457 | <tt class="function">str()</tt> of the <tt class="module">locale</tt> module are affected by that | |
458 | category. All other numeric formatting operations are not | |
459 | affected. | |
460 | </dd></dl> | |
461 | ||
462 | <P> | |
463 | <dl><dt><b><tt id='l2h-2384' xml:id='l2h-2384'>LC_ALL</tt></b></dt> | |
464 | <dd> | |
465 | Combination of all locale settings. If this flag is used when the | |
466 | locale is changed, setting the locale for all categories is | |
467 | attempted. If that fails for any category, no category is changed at | |
468 | all. When the locale is retrieved using this flag, a string | |
469 | indicating the setting for all categories is returned. This string | |
470 | can be later used to restore the settings. | |
471 | </dd></dl> | |
472 | ||
473 | <P> | |
474 | <dl><dt><b><tt id='l2h-2385' xml:id='l2h-2385'>CHAR_MAX</tt></b></dt> | |
475 | <dd> | |
476 | This is a symbolic constant used for different values returned by | |
477 | <tt class="function">localeconv()</tt>. | |
478 | </dd></dl> | |
479 | ||
480 | <P> | |
481 | The <tt class="function">nl_langinfo</tt> function accepts one of the following keys. | |
482 | Most descriptions are taken from the corresponding description in the | |
483 | GNU C library. | |
484 | ||
485 | <P> | |
486 | <dl><dt><b><tt id='l2h-2386' xml:id='l2h-2386'>CODESET</tt></b></dt> | |
487 | <dd> | |
488 | Return a string with the name of the character encoding used in the | |
489 | selected locale. | |
490 | </dd></dl> | |
491 | ||
492 | <P> | |
493 | <dl><dt><b><tt id='l2h-2387' xml:id='l2h-2387'>D_T_FMT</tt></b></dt> | |
494 | <dd> | |
495 | Return a string that can be used as a format string for strftime(3) to | |
496 | represent time and date in a locale-specific way. | |
497 | </dd></dl> | |
498 | ||
499 | <P> | |
500 | <dl><dt><b><tt id='l2h-2388' xml:id='l2h-2388'>D_FMT</tt></b></dt> | |
501 | <dd> | |
502 | Return a string that can be used as a format string for strftime(3) to | |
503 | represent a date in a locale-specific way. | |
504 | </dd></dl> | |
505 | ||
506 | <P> | |
507 | <dl><dt><b><tt id='l2h-2389' xml:id='l2h-2389'>T_FMT</tt></b></dt> | |
508 | <dd> | |
509 | Return a string that can be used as a format string for strftime(3) to | |
510 | represent a time in a locale-specific way. | |
511 | </dd></dl> | |
512 | ||
513 | <P> | |
514 | <dl><dt><b><tt id='l2h-2390' xml:id='l2h-2390'>T_FMT_AMPM</tt></b></dt> | |
515 | <dd> | |
516 | The return value can be used as a format string for `strftime' to | |
517 | represent time in the am/pm format. | |
518 | </dd></dl> | |
519 | ||
520 | <P> | |
521 | <dl><dt><b><tt id='l2h-2391' xml:id='l2h-2391'>DAY_1 ... DAY_7</tt></b></dt> | |
522 | <dd> | |
523 | Return name of the n-th day of the week. <span class="warning"><b class="label">Warning:</b> | |
524 | This | |
525 | follows the US convention of <tt class="constant">DAY_1</tt> being Sunday, not the | |
526 | international convention (ISO 8601) that Monday is the first day of | |
527 | the week.</span> | |
528 | </dd></dl> | |
529 | ||
530 | <P> | |
531 | <dl><dt><b><tt id='l2h-2392' xml:id='l2h-2392'>ABDAY_1 ... ABDAY_7</tt></b></dt> | |
532 | <dd> | |
533 | Return abbreviated name of the n-th day of the week. | |
534 | </dd></dl> | |
535 | ||
536 | <P> | |
537 | <dl><dt><b><tt id='l2h-2393' xml:id='l2h-2393'>MON_1 ... MON_12</tt></b></dt> | |
538 | <dd> | |
539 | Return name of the n-th month. | |
540 | </dd></dl> | |
541 | ||
542 | <P> | |
543 | <dl><dt><b><tt id='l2h-2394' xml:id='l2h-2394'>ABMON_1 ... ABMON_12</tt></b></dt> | |
544 | <dd> | |
545 | Return abbreviated name of the n-th month. | |
546 | </dd></dl> | |
547 | ||
548 | <P> | |
549 | <dl><dt><b><tt id='l2h-2395' xml:id='l2h-2395'>RADIXCHAR</tt></b></dt> | |
550 | <dd> | |
551 | Return radix character (decimal dot, decimal comma, etc.) | |
552 | </dd></dl> | |
553 | ||
554 | <P> | |
555 | <dl><dt><b><tt id='l2h-2396' xml:id='l2h-2396'>THOUSEP</tt></b></dt> | |
556 | <dd> | |
557 | Return separator character for thousands (groups of three digits). | |
558 | </dd></dl> | |
559 | ||
560 | <P> | |
561 | <dl><dt><b><tt id='l2h-2397' xml:id='l2h-2397'>YESEXPR</tt></b></dt> | |
562 | <dd> | |
563 | Return a regular expression that can be used with the regex | |
564 | function to recognize a positive response to a yes/no question. | |
565 | <span class="warning"><b class="label">Warning:</b> | |
566 | The expression is in the syntax suitable for the | |
567 | <tt class="cfunction">regex()</tt> function from the C library, which might differ | |
568 | from the syntax used in <tt class="module"><a href="module-re.html">re</a></tt>.</span> | |
569 | </dd></dl> | |
570 | ||
571 | <P> | |
572 | <dl><dt><b><tt id='l2h-2398' xml:id='l2h-2398'>NOEXPR</tt></b></dt> | |
573 | <dd> | |
574 | Return a regular expression that can be used with the regex(3) | |
575 | function to recognize a negative response to a yes/no question. | |
576 | </dd></dl> | |
577 | ||
578 | <P> | |
579 | <dl><dt><b><tt id='l2h-2399' xml:id='l2h-2399'>CRNCYSTR</tt></b></dt> | |
580 | <dd> | |
581 | Return the currency symbol, preceded by "-" if the symbol should | |
582 | appear before the value, "+" if the symbol should appear after the | |
583 | value, or "." if the symbol should replace the radix character. | |
584 | </dd></dl> | |
585 | ||
586 | <P> | |
587 | <dl><dt><b><tt id='l2h-2400' xml:id='l2h-2400'>ERA</tt></b></dt> | |
588 | <dd> | |
589 | The return value represents the era used in the current locale. | |
590 | ||
591 | <P> | |
592 | Most locales do not define this value. An example of a locale which | |
593 | does define this value is the Japanese one. In Japan, the traditional | |
594 | representation of dates includes the name of the era corresponding to | |
595 | the then-emperor's reign. | |
596 | ||
597 | <P> | |
598 | Normally it should not be necessary to use this value directly. | |
599 | Specifying the <code>E</code> modifier in their format strings causes the | |
600 | <tt class="function">strftime</tt> function to use this information. The format of the | |
601 | returned string is not specified, and therefore you should not assume | |
602 | knowledge of it on different systems. | |
603 | </dd></dl> | |
604 | ||
605 | <P> | |
606 | <dl><dt><b><tt id='l2h-2401' xml:id='l2h-2401'>ERA_YEAR</tt></b></dt> | |
607 | <dd> | |
608 | The return value gives the year in the relevant era of the locale. | |
609 | </dd></dl> | |
610 | ||
611 | <P> | |
612 | <dl><dt><b><tt id='l2h-2402' xml:id='l2h-2402'>ERA_D_T_FMT</tt></b></dt> | |
613 | <dd> | |
614 | This return value can be used as a format string for | |
615 | <tt class="function">strftime</tt> to represent dates and times in a locale-specific | |
616 | era-based way. | |
617 | </dd></dl> | |
618 | ||
619 | <P> | |
620 | <dl><dt><b><tt id='l2h-2403' xml:id='l2h-2403'>ERA_D_FMT</tt></b></dt> | |
621 | <dd> | |
622 | This return value can be used as a format string for | |
623 | <tt class="function">strftime</tt> to represent time in a locale-specific era-based | |
624 | way. | |
625 | </dd></dl> | |
626 | ||
627 | <P> | |
628 | <dl><dt><b><tt id='l2h-2404' xml:id='l2h-2404'>ALT_DIGITS</tt></b></dt> | |
629 | <dd> | |
630 | The return value is a representation of up to 100 values used to | |
631 | represent the values 0 to 99. | |
632 | </dd></dl> | |
633 | ||
634 | <P> | |
635 | Example: | |
636 | ||
637 | <P> | |
638 | <div class="verbatim"><pre> | |
639 | >>> import locale | |
640 | >>> loc = locale.getlocale(locale.LC_ALL) # get current locale | |
641 | >>> locale.setlocale(locale.LC_ALL, 'de_DE') # use German locale; name might vary with platform | |
642 | >>> locale.strcoll('f\xe4n', 'foo') # compare a string containing an umlaut | |
643 | >>> locale.setlocale(locale.LC_ALL, '') # use user's preferred locale | |
644 | >>> locale.setlocale(locale.LC_ALL, 'C') # use default (C) locale | |
645 | >>> locale.setlocale(locale.LC_ALL, loc) # restore saved locale | |
646 | </pre></div> | |
647 | ||
648 | <P> | |
649 | ||
650 | <p><br /></p><hr class='online-navigation' /> | |
651 | <div class='online-navigation'> | |
652 | <!--Table of Child-Links--> | |
653 | <A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></a> | |
654 | ||
655 | <UL CLASS="ChildLinks"> | |
656 | <LI><A href="node323.html">6.27.1 Background, details, hints, tips and caveats</a> | |
657 | <LI><A href="embedding-locale.html">6.27.2 For extension writers and programs that embed Python</a> | |
658 | <LI><A href="locale-gettext.html">6.27.3 Access to message catalogs</a> | |
659 | </ul> | |
660 | <!--End of Table of Child-Links--> | |
661 | </div> | |
662 | ||
663 | <DIV CLASS="navigation"> | |
664 | <div class='online-navigation'> | |
665 | <p></p><hr /> | |
666 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
667 | <tr> | |
668 | <td class='online-navigation'><a rel="prev" title="6.26.1 Example" | |
669 | href="shutil-example.html"><img src='../icons/previous.png' | |
670 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
671 | <td class='online-navigation'><a rel="parent" title="6. Generic Operating System" | |
672 | href="allos.html"><img src='../icons/up.png' | |
673 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
674 | <td class='online-navigation'><a rel="next" title="6.27.1 Background, details, hints," | |
675 | href="node323.html"><img src='../icons/next.png' | |
676 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
677 | <td align="center" width="100%">Python Library Reference</td> | |
678 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
679 | href="contents.html"><img src='../icons/contents.png' | |
680 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
681 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
682 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
683 | <td class='online-navigation'><a rel="index" title="Index" | |
684 | href="genindex.html"><img src='../icons/index.png' | |
685 | border='0' height='32' alt='Index' width='32' /></A></td> | |
686 | </tr></table> | |
687 | <div class='online-navigation'> | |
688 | <b class="navlabel">Previous:</b> | |
689 | <a class="sectref" rel="prev" href="shutil-example.html">6.26.1 Example</A> | |
690 | <b class="navlabel">Up:</b> | |
691 | <a class="sectref" rel="parent" href="allos.html">6. Generic Operating System</A> | |
692 | <b class="navlabel">Next:</b> | |
693 | <a class="sectref" rel="next" href="node323.html">6.27.1 Background, details, hints,</A> | |
694 | </div> | |
695 | </div> | |
696 | <hr /> | |
697 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
698 | </DIV> | |
699 | <!--End of Navigation Panel--> | |
700 | <ADDRESS> | |
701 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
702 | </ADDRESS> | |
703 | </BODY> | |
704 | </HTML> |