blob: 72dc69c42ea9326ef746f0b68821cbe5af8a1428 [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{locale} ---
Fred Drakec3845a11999-04-21 17:18:04 +00002 Internationalization services}
3
Fred Drakeb91e9341998-07-23 17:59:49 +00004\declaremodule{standard}{locale}
Fred Drakeb91e9341998-07-23 17:59:49 +00005\modulesynopsis{Internationalization services.}
Fred Drake1491cac2000-10-25 20:59:52 +00006\moduleauthor{Martin von L\"owis}{loewis@informatik.hu-berlin.de}
7\sectionauthor{Martin von L\"owis}{loewis@informatik.hu-berlin.de}
Fred Drakeb91e9341998-07-23 17:59:49 +00008
Guido van Rossumbc12f781997-11-20 21:04:27 +00009
Fred Drake1491cac2000-10-25 20:59:52 +000010The \module{locale} module opens access to the \POSIX{} locale
11database and functionality. The \POSIX{} locale mechanism allows
12programmers to deal with certain cultural issues in an application,
13without requiring the programmer to know all the specifics of each
14country where the software is executed.
Guido van Rossumbc12f781997-11-20 21:04:27 +000015
Fred Drake193338a1998-03-10 04:23:12 +000016The \module{locale} module is implemented on top of the
17\module{_locale}\refbimodindex{_locale} module, which in turn uses an
Fred Drakec3845a11999-04-21 17:18:04 +000018ANSI C locale implementation if available.
Guido van Rossumbc12f781997-11-20 21:04:27 +000019
Fred Drake193338a1998-03-10 04:23:12 +000020The \module{locale} module defines the following exception and
21functions:
Guido van Rossumbc12f781997-11-20 21:04:27 +000022
Guido van Rossumbc12f781997-11-20 21:04:27 +000023
Fred Drake1491cac2000-10-25 20:59:52 +000024\begin{excdesc}{Error}
25 Exception raised when \function{setlocale()} fails.
26\end{excdesc}
Guido van Rossumbc12f781997-11-20 21:04:27 +000027
Fred Drake1491cac2000-10-25 20:59:52 +000028\begin{funcdesc}{setlocale}{category\optional{, locale}}
29 If \var{locale} is specified, it may be a string, a tuple of the
30 form \code{(\var{language code}, \var{encoding})}, or \code{None}.
31 If it is a tuple, it is converted to a string using the locale
32 aliasing engine. If \var{locale} is given and not \code{None},
33 \function{setlocale()} modifies the locale setting for the
34 \var{category}. The available categories are listed in the data
35 description below. The value is the name of a locale. An empty
36 string specifies the user's default settings. If the modification of
37 the locale fails, the exception \exception{Error} is raised. If
38 successful, the new locale setting is returned.
Guido van Rossumbc12f781997-11-20 21:04:27 +000039
Fred Drake1491cac2000-10-25 20:59:52 +000040 If \var{locale} is omitted or \code{None}, the current setting for
41 \var{category} is returned.
42
43 \function{setlocale()} is not thread safe on most systems.
44 Applications typically start with a call of
45
Fred Drake19479911998-02-13 06:58:54 +000046\begin{verbatim}
Guido van Rossumbc12f781997-11-20 21:04:27 +000047import locale
Fred Drakec01f6e62000-11-30 07:13:58 +000048locale.setlocale(locale.LC_ALL, '')
Fred Drake19479911998-02-13 06:58:54 +000049\end{verbatim}
Guido van Rossumbc12f781997-11-20 21:04:27 +000050
Fred Drake1491cac2000-10-25 20:59:52 +000051 This sets the locale for all categories to the user's default
52 setting (typically specified in the \envvar{LANG} environment
53 variable). If the locale is not changed thereafter, using
54 multithreading should not cause problems.
55
56 \versionchanged[Added support for tuple values of the \var{locale}
57 parameter]{2.0}
58\end{funcdesc}
Fred Drake193338a1998-03-10 04:23:12 +000059
Guido van Rossumbc12f781997-11-20 21:04:27 +000060\begin{funcdesc}{localeconv}{}
Fred Drake1491cac2000-10-25 20:59:52 +000061 Returns the database of of the local conventions as a dictionary.
62 This dictionary has the following strings as keys:
Fred Drake193338a1998-03-10 04:23:12 +000063
Fred Drakec01f6e62000-11-30 07:13:58 +000064 \begin{tableiii}{l|l|p{3in}}{constant}{Key}{Category}{Meaning}
65 \lineiii{LC_NUMERIC}{\code{'decimal_point'}}
66 {Decimal point character.}
67 \lineiii{}{\code{'grouping'}}
68 {Sequence of numbers specifying which relative positions
69 the \code{'thousands_sep'} is expected. If the sequence is
70 terminated with \constant{CHAR_MAX}, no further grouping
71 is performed. If the sequence terminates with a \code{0},
72 the last group size is repeatedly used.}
73 \lineiii{}{\code{'thousands_sep'}}
74 {Character used between groups.}\hline
75 \lineiii{LC_MONETARY}{\code{'int_curr_symbol'}}
76 {International currency symbol.}
77 \lineiii{}{\code{'currency_symbol'}}
78 {Local currency symbol.}
79 \lineiii{}{\code{'mon_decimal_point'}}
80 {Decimal point used for monetary values.}
81 \lineiii{}{\code{'mon_thousands_sep'}}
82 {Group separator used for monetary values.}
83 \lineiii{}{\code{'mon_grouping'}}
84 {Equivalent to \code{'grouping'}, used for monetary
85 values.}
86 \lineiii{}{\code{'positive_sign'}}
87 {Symbol used to annotate a positive monetary value.}
88 \lineiii{}{\code{'negative_sign'}}
89 {Symbol used to annotate a nnegative monetary value.}
90 \lineiii{}{\code{'frac_digits'}}
91 {Number of fractional digits used in local formatting
92 of monetary values.}
93 \lineiii{}{\code{'int_frac_digits'}}
94 {Number of fractional digits used in international
95 formatting of monetary values.}
96 \end{tableiii}
Fred Drake193338a1998-03-10 04:23:12 +000097
Fred Drakec01f6e62000-11-30 07:13:58 +000098 The possible values for \code{'p_sign_posn'} and
99 \code{'n_sign_posn'} are given below.
Fred Drake1491cac2000-10-25 20:59:52 +0000100
101 \begin{tableii}{c|l}{code}{Value}{Explanation}
102 \lineii{0}{Currency and value are surrounded by parentheses.}
103 \lineii{1}{The sign should precede the value and currency symbol.}
104 \lineii{2}{The sign should follow the value and currency symbol.}
105 \lineii{3}{The sign should immediately precede the value.}
106 \lineii{4}{The sign should immediately follow the value.}
Fred Drakec01f6e62000-11-30 07:13:58 +0000107 \lineii{\constant{LC_MAX}}{Nothing is specified in this locale.}
Fred Drake1491cac2000-10-25 20:59:52 +0000108 \end{tableii}
Guido van Rossumbc12f781997-11-20 21:04:27 +0000109\end{funcdesc}
110
Martin v. Löwis9b75dca2001-08-10 13:58:50 +0000111\begin{funcdesc}{nl_langinfo}{option}
112
113Return some locale-specific information as a string. This function is
114not available on all systems, and the set of possible options might
115also vary across platforms. The possible argument values are numbers,
116for which symbolic constants are available in the locale module.
117
118\end{funcdesc}
119
Fred Drake1491cac2000-10-25 20:59:52 +0000120\begin{funcdesc}{getdefaultlocale}{\optional{envvars}}
121 Tries to determine the default locale settings and returns
122 them as a tuple of the form \code{(\var{language code},
123 \var{encoding})}.
124
125 According to \POSIX, a program which has not called
126 \code{setlocale(LC_ALL, '')} runs using the portable \code{'C'}
127 locale. Calling \code{setlocale(LC_ALL, '')} lets it use the
128 default locale as defined by the \envvar{LANG} variable. Since we
129 do not want to interfere with the current locale setting we thus
130 emulate the behavior in the way described above.
131
132 To maintain compatibility with other platforms, not only the
133 \envvar{LANG} variable is tested, but a list of variables given as
134 envvars parameter. The first found to be defined will be
135 used. \var{envvars} defaults to the search path used in GNU gettext;
136 it must always contain the variable name \samp{LANG}. The GNU
137 gettext search path contains \code{'LANGUAGE'}, \code{'LC_ALL'},
Fred Drakef69868f2001-07-20 19:03:44 +0000138 \code{'LC_CTYPE'}, and \code{'LANG'}, in that order.
Fred Drake1491cac2000-10-25 20:59:52 +0000139
140 Except for the code \code{'C'}, the language code corresponds to
141 \rfc{1766}. \var{language code} and \var{encoding} may be
142 \code{None} if their values cannot be determined.
143 \versionadded{2.0}
144\end{funcdesc}
145
146\begin{funcdesc}{getlocale}{\optional{category}}
147 Returns the current setting for the given locale category as
148 tuple (language code, encoding). \var{category} may be one of the
149 \constant{LC_*} values except \constant{LC_ALL}. It defaults to
150 \constant{LC_CTYPE}.
151
152 Except for the code \code{'C'}, the language code corresponds to
153 \rfc{1766}. \var{language code} and \var{encoding} may be
154 \code{None} if their values cannot be determined.
155 \versionadded{2.0}
156\end{funcdesc}
157
158\begin{funcdesc}{normalize}{localename}
159 Returns a normalized locale code for the given locale name. The
160 returned locale code is formatted for use with
161 \function{setlocale()}. If normalization fails, the original name
162 is returned unchanged.
163
164 If the given encoding is not known, the function defaults to
165 the default encoding for the locale code just like
166 \function{setlocale()}.
167 \versionadded{2.0}
168\end{funcdesc}
169
170\begin{funcdesc}{resetlocale}{\optional{category}}
171 Sets the locale for \var{category} to the default setting.
172
173 The default setting is determined by calling
174 \function{getdefaultlocale()}. \var{category} defaults to
175 \constant{LC_ALL}.
176 \versionadded{2.0}
177\end{funcdesc}
178
179\begin{funcdesc}{strcoll}{string1, string2}
180 Compares two strings according to the current
181 \constant{LC_COLLATE} setting. As any other compare function,
182 returns a negative, or a positive value, or \code{0}, depending on
183 whether \var{string1} collates before or after \var{string2} or is
184 equal to it.
Guido van Rossumbc12f781997-11-20 21:04:27 +0000185\end{funcdesc}
186
187\begin{funcdesc}{strxfrm}{string}
Fred Drake1491cac2000-10-25 20:59:52 +0000188 Transforms a string to one that can be used for the built-in
189 function \function{cmp()}\bifuncindex{cmp}, and still returns
190 locale-aware results. This function can be used when the same
191 string is compared repeatedly, e.g. when collating a sequence of
192 strings.
Guido van Rossumbc12f781997-11-20 21:04:27 +0000193\end{funcdesc}
194
Fred Drake1491cac2000-10-25 20:59:52 +0000195\begin{funcdesc}{format}{format, val\optional{, grouping}}
196 Formats a number \var{val} according to the current
197 \constant{LC_NUMERIC} setting. The format follows the conventions
198 of the \code{\%} operator. For floating point values, the decimal
199 point is modified if appropriate. If \var{grouping} is true, also
200 takes the grouping into account.
Guido van Rossumbc12f781997-11-20 21:04:27 +0000201\end{funcdesc}
202
203\begin{funcdesc}{str}{float}
Fred Drake1491cac2000-10-25 20:59:52 +0000204 Formats a floating point number using the same format as the
205 built-in function \code{str(\var{float})}, but takes the decimal
206 point into account.
Guido van Rossumbc12f781997-11-20 21:04:27 +0000207\end{funcdesc}
208
209\begin{funcdesc}{atof}{string}
Fred Drake1491cac2000-10-25 20:59:52 +0000210 Converts a string to a floating point number, following the
211 \constant{LC_NUMERIC} settings.
Guido van Rossumbc12f781997-11-20 21:04:27 +0000212\end{funcdesc}
213
214\begin{funcdesc}{atoi}{string}
Fred Drake1491cac2000-10-25 20:59:52 +0000215 Converts a string to an integer, following the
216 \constant{LC_NUMERIC} conventions.
Guido van Rossumbc12f781997-11-20 21:04:27 +0000217\end{funcdesc}
218
219\begin{datadesc}{LC_CTYPE}
Fred Drake304474f1997-12-17 15:30:07 +0000220\refstmodindex{string}
Fred Drake1491cac2000-10-25 20:59:52 +0000221 Locale category for the character type functions. Depending on the
222 settings of this category, the functions of module
223 \refmodule{string} dealing with case change their behaviour.
Guido van Rossumbc12f781997-11-20 21:04:27 +0000224\end{datadesc}
225
226\begin{datadesc}{LC_COLLATE}
Fred Drake1491cac2000-10-25 20:59:52 +0000227 Locale category for sorting strings. The functions
228 \function{strcoll()} and \function{strxfrm()} of the
229 \module{locale} module are affected.
Guido van Rossumbc12f781997-11-20 21:04:27 +0000230\end{datadesc}
231
232\begin{datadesc}{LC_TIME}
Fred Drake1491cac2000-10-25 20:59:52 +0000233 Locale category for the formatting of time. The function
234 \function{time.strftime()} follows these conventions.
Guido van Rossumbc12f781997-11-20 21:04:27 +0000235\end{datadesc}
236
237\begin{datadesc}{LC_MONETARY}
Fred Drake1491cac2000-10-25 20:59:52 +0000238 Locale category for formatting of monetary values. The available
239 options are available from the \function{localeconv()} function.
Guido van Rossumbc12f781997-11-20 21:04:27 +0000240\end{datadesc}
241
242\begin{datadesc}{LC_MESSAGES}
Fred Drake1491cac2000-10-25 20:59:52 +0000243 Locale category for message display. Python currently does not
244 support application specific locale-aware messages. Messages
245 displayed by the operating system, like those returned by
246 \function{os.strerror()} might be affected by this category.
Guido van Rossumbc12f781997-11-20 21:04:27 +0000247\end{datadesc}
248
249\begin{datadesc}{LC_NUMERIC}
Fred Drake1491cac2000-10-25 20:59:52 +0000250 Locale category for formatting numbers. The functions
251 \function{format()}, \function{atoi()}, \function{atof()} and
252 \function{str()} of the \module{locale} module are affected by that
253 category. All other numeric formatting operations are not
254 affected.
Guido van Rossumbc12f781997-11-20 21:04:27 +0000255\end{datadesc}
256
257\begin{datadesc}{LC_ALL}
Fred Drake1491cac2000-10-25 20:59:52 +0000258 Combination of all locale settings. If this flag is used when the
259 locale is changed, setting the locale for all categories is
260 attempted. If that fails for any category, no category is changed at
261 all. When the locale is retrieved using this flag, a string
262 indicating the setting for all categories is returned. This string
263 can be later used to restore the settings.
Guido van Rossumbc12f781997-11-20 21:04:27 +0000264\end{datadesc}
265
266\begin{datadesc}{CHAR_MAX}
Fred Drake1491cac2000-10-25 20:59:52 +0000267 This is a symbolic constant used for different values returned by
268 \function{localeconv()}.
Guido van Rossumbc12f781997-11-20 21:04:27 +0000269\end{datadesc}
270
Martin v. Löwis9b75dca2001-08-10 13:58:50 +0000271The \function{nl_langinfo} function accepts one of the following keys.
272Most descriptions are taken from the corresponding description in the
273GNU C library.
274
275\begin{datadesc}{CODESET}
276Return a string with the name of the character encoding used in the
277selected locale.
278\end{datadesc}
279
280\begin{datadesc}{D_T_FMT}
281Return a string that can be used as a format string for strftime(3) to
282represent time and date in a locale-specific way.
283\end{datadesc}
284
285\begin{datadesc}{D_FMT}
286Return a string that can be used as a format string for strftime(3) to
287represent a date in a locale-specific way.
288\end{datadesc}
289
290\begin{datadesc}{T_FMT}
291Return a string that can be used as a format string for strftime(3) to
292represent a time in a locale-specific way.
293\end{datadesc}
294
295\begin{datadesc}{T_FMT_AMPM}
296The return value can be used as a format string for `strftime' to
297represent time in the am/pm format.
298\end{datadesc}
299
300\begin{datadesc}{DAY_1 ... DAY_7}
Fred Drake0aa811c2001-10-20 04:24:09 +0000301Return name of the n-th day of the week. \warning{This
Fred Drakeb802a1e2001-09-27 04:16:27 +0000302follows the US convention of \constant{DAY_1} being Sunday, not the
303international convention (ISO 8601) that Monday is the first day of
Fred Drake0aa811c2001-10-20 04:24:09 +0000304the week.}
Martin v. Löwis9b75dca2001-08-10 13:58:50 +0000305\end{datadesc}
306
307\begin{datadesc}{ABDAY_1 ... ABDAY_7}
308Return abbreviated name of the n-th day of the week.
309\end{datadesc}
310
311\begin{datadesc}{MON_1 ... MON_12}
312Return name of the n-th month.
313\end{datadesc}
314
315\begin{datadesc}{ABMON_1 ... ABMON_12}
316Return abbreviated name of the n-th month.
317\end{datadesc}
318
319\begin{datadesc}{RADIXCHAR}
320Return radix character (decimal dot, decimal comma, etc.)
321\end{datadesc}
322
323\begin{datadesc}{THOUSEP}
324Return separator character for thousands (groups of three digits).
325\end{datadesc}
326
327\begin{datadesc}{YESEXPR}
328Return a regular expression that can be used with the regex
329function to recognize a positive response to a yes/no question.
Fred Drake0aa811c2001-10-20 04:24:09 +0000330\warning{The expression is in the syntax suitable for the
Fred Drakeb802a1e2001-09-27 04:16:27 +0000331\cfunction{regex()} function from the C library, which might differ
Fred Drake0aa811c2001-10-20 04:24:09 +0000332from the syntax used in \refmodule{re}.}
Martin v. Löwis9b75dca2001-08-10 13:58:50 +0000333\end{datadesc}
334
335\begin{datadesc}{NOEXPR}
336Return a regular expression that can be used with the regex(3)
337function to recognize a negative response to a yes/no question.
338\end{datadesc}
339
340\begin{datadesc}{CRNCYSTR}
341Return the currency symbol, preceded by "-" if the symbol should
342appear before the value, "+" if the symbol should appear after the
343value, or "." if the symbol should replace the radix character.
344\end{datadesc}
345
346\begin{datadesc}{ERA}
347The return value represents the era used in the current locale.
348
349Most locales do not define this value. An example of a locale which
350does define this value is the Japanese one. In Japan, the traditional
351representation of dates includes the name of the era corresponding to
352the then-emperor's reign.
353
354Normally it should not be necessary to use this value directly.
355Specifying the \code{E} modifier in their format strings causes the
356\function{strftime} function to use this information. The format of the
357returned string is not specified, and therefore you should not assume
358knowledge of it on different systems.
359\end{datadesc}
360
361\begin{datadesc}{ERA_YEAR}
362The return value gives the year in the relevant era of the locale.
363\end{datadesc}
364
365\begin{datadesc}{ERA_D_T_FMT}
366This return value can be used as a format string for
367\function{strftime} to represent dates and times in a locale-specific
368era-based way.
369\end{datadesc}
370
371\begin{datadesc}{ERA_D_FMT}
372This return value can be used as a format string for
373\function{strftime} to represent time in a locale-specific era-based
374way.
375\end{datadesc}
376
377\begin{datadesc}{ALT_DIGITS}
378The return value is a representation of up to 100 values used to
379represent the values 0 to 99.
380\end{datadesc}
381
Guido van Rossumbc12f781997-11-20 21:04:27 +0000382Example:
383
Fred Drake19479911998-02-13 06:58:54 +0000384\begin{verbatim}
Guido van Rossumbc12f781997-11-20 21:04:27 +0000385>>> import locale
Guido van Rossumd028ca91998-02-22 04:41:51 +0000386>>> loc = locale.setlocale(locale.LC_ALL) # get current locale
Fred Drakec01f6e62000-11-30 07:13:58 +0000387>>> locale.setlocale(locale.LC_ALL, 'de') # use German locale
Ka-Ping Yeefa004ad2001-01-24 17:19:08 +0000388>>> locale.strcoll('f\xe4n', 'foo') # compare a string containing an umlaut
Fred Drakec01f6e62000-11-30 07:13:58 +0000389>>> locale.setlocale(locale.LC_ALL, '') # use user's preferred locale
390>>> locale.setlocale(locale.LC_ALL, 'C') # use default (C) locale
Guido van Rossumd028ca91998-02-22 04:41:51 +0000391>>> locale.setlocale(locale.LC_ALL, loc) # restore saved locale
Fred Drake19479911998-02-13 06:58:54 +0000392\end{verbatim}
Guido van Rossum3ffb7151998-02-22 04:23:51 +0000393
Fred Drake1491cac2000-10-25 20:59:52 +0000394
Guido van Rossum3ffb7151998-02-22 04:23:51 +0000395\subsection{Background, details, hints, tips and caveats}
396
397The C standard defines the locale as a program-wide property that may
398be relatively expensive to change. On top of that, some
399implementation are broken in such a way that frequent locale changes
400may cause core dumps. This makes the locale somewhat painful to use
401correctly.
402
Fred Drake9fee0711998-04-03 06:21:23 +0000403Initially, when a program is started, the locale is the \samp{C} locale, no
Guido van Rossum3ffb7151998-02-22 04:23:51 +0000404matter what the user's preferred locale is. The program must
405explicitly say that it wants the user's preferred locale settings by
Fred Drakec01f6e62000-11-30 07:13:58 +0000406calling \code{setlocale(LC_ALL, '')}.
Guido van Rossum3ffb7151998-02-22 04:23:51 +0000407
Fred Drake193338a1998-03-10 04:23:12 +0000408It is generally a bad idea to call \function{setlocale()} in some library
Guido van Rossum3ffb7151998-02-22 04:23:51 +0000409routine, since as a side effect it affects the entire program. Saving
410and restoring it is almost as bad: it is expensive and affects other
411threads that happen to run before the settings have been restored.
412
413If, when coding a module for general use, you need a locale
414independent version of an operation that is affected by the locale
Fred Drake193338a1998-03-10 04:23:12 +0000415(e.g. \function{string.lower()}, or certain formats used with
416\function{time.strftime()})), you will have to find a way to do it
417without using the standard library routine. Even better is convincing
418yourself that using locale settings is okay. Only as a last resort
Fred Drake9fee0711998-04-03 06:21:23 +0000419should you document that your module is not compatible with
420non-\samp{C} locale settings.
Guido van Rossum3ffb7151998-02-22 04:23:51 +0000421
Fred Drake193338a1998-03-10 04:23:12 +0000422The case conversion functions in the
Fred Drakee9735ac2001-05-10 15:05:03 +0000423\refmodule{string}\refstmodindex{string} module are affected by the
424locale settings. When a call to the \function{setlocale()} function
425changes the \constant{LC_CTYPE} settings, the variables
Fred Drake193338a1998-03-10 04:23:12 +0000426\code{string.lowercase}, \code{string.uppercase} and
Fred Drakee9735ac2001-05-10 15:05:03 +0000427\code{string.letters} are recalculated. Note that this code that uses
428these variable through `\keyword{from} ... \keyword{import} ...',
429e.g.\ \code{from string import letters}, is not affected by subsequent
430\function{setlocale()} calls.
Guido van Rossum3ffb7151998-02-22 04:23:51 +0000431
432The only way to perform numeric operations according to the locale
433is to use the special functions defined by this module:
Fred Drake193338a1998-03-10 04:23:12 +0000434\function{atof()}, \function{atoi()}, \function{format()},
435\function{str()}.
Guido van Rossum3ffb7151998-02-22 04:23:51 +0000436
Fred Drake1491cac2000-10-25 20:59:52 +0000437\subsection{For extension writers and programs that embed Python
438 \label{embedding-locale}}
Guido van Rossum3ffb7151998-02-22 04:23:51 +0000439
Fred Drake193338a1998-03-10 04:23:12 +0000440Extension modules should never call \function{setlocale()}, except to
441find out what the current locale is. But since the return value can
442only be used portably to restore it, that is not very useful (except
Fred Drake9fee0711998-04-03 06:21:23 +0000443perhaps to find out whether or not the locale is \samp{C}).
Guido van Rossum3ffb7151998-02-22 04:23:51 +0000444
445When Python is embedded in an application, if the application sets the
446locale to something specific before initializing Python, that is
447generally okay, and Python will use whatever locale is set,
Fred Drake9fee0711998-04-03 06:21:23 +0000448\emph{except} that the \constant{LC_NUMERIC} locale should always be
449\samp{C}.
Guido van Rossum3ffb7151998-02-22 04:23:51 +0000450
Fred Drake85b56831999-07-01 16:31:03 +0000451The \function{setlocale()} function in the \module{locale} module
Thomas Woutersf8316632000-07-16 19:01:10 +0000452gives the Python programmer the impression that you can manipulate the
Fred Drakec3845a11999-04-21 17:18:04 +0000453\constant{LC_NUMERIC} locale setting, but this not the case at the C
454level: C code will always find that the \constant{LC_NUMERIC} locale
Fred Drake9fee0711998-04-03 06:21:23 +0000455setting is \samp{C}. This is because too much would break when the
Guido van Rossum3ffb7151998-02-22 04:23:51 +0000456decimal point character is set to something else than a period
457(e.g. the Python parser would break). Caveat: threads that run
458without holding Python's global interpreter lock may occasionally find
459that the numeric locale setting differs; this is because the only
460portable way to implement this feature is to set the numeric locale
461settings to what the user requests, extract the relevant
Fred Drake9fee0711998-04-03 06:21:23 +0000462characteristics, and then restore the \samp{C} numeric locale.
Guido van Rossum3ffb7151998-02-22 04:23:51 +0000463
Fred Drake193338a1998-03-10 04:23:12 +0000464When Python code uses the \module{locale} module to change the locale,
Fred Draked8a41e61999-02-19 17:54:10 +0000465this also affects the embedding application. If the embedding
Guido van Rossum3ffb7151998-02-22 04:23:51 +0000466application doesn't want this to happen, it should remove the
Fred Drake193338a1998-03-10 04:23:12 +0000467\module{_locale} extension module (which does all the work) from the
468table of built-in modules in the \file{config.c} file, and make sure
469that the \module{_locale} module is not accessible as a shared library.