<!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN">
<link rel=
"STYLESHEET" href=
"whatsnew24.css" type='text/css'
/>
<link rel=
"SHORTCUT ICON" href=
"../icons/pyfav.png" type=
"image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index'
/>
<link rel=
"first" href=
"whatsnew24.html" title='What's New in Python
2.4'
/>
<link rel='contents' href='contents.html'
title=
"Contents" />
<link rel='last' href='about.html' title='About this document...'
/>
<link rel='help' href='about.html' title='About this document...'
/>
<link rel=
"next" href=
"node12.html" />
<link rel=
"prev" href=
"node10.html" />
<link rel=
"parent" href=
"whatsnew24.html" />
<link rel=
"next" href=
"node12.html" />
<meta name='aesop' content='information'
/>
<title>10 PEP
331: Locale-Independent Float/String Conversions
</title>
<div id='top-navigation-panel' xml:id='top-navigation-panel'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"9 PEP 328: Multi-line"
href=
"node10.html"><img src='../icons/previous.png'
border='
0' height='
32' alt='Previous Page' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"parent" title=
"What's New in Python"
href=
"whatsnew24.html"><img src='../icons/up.png'
border='
0' height='
32' alt='Up One Level' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"next" title=
"11 Other Language Changes"
href=
"node12.html"><img src='../icons/next.png'
border='
0' height='
32' alt='Next Page' width='
32'
/></A></td>
<td align=
"center" width=
"100%">What's New in Python
2.4</td>
<td class='online-navigation'
><a rel=
"contents" title=
"Table of Contents"
href=
"contents.html"><img src='../icons/contents.png'
border='
0' height='
32' alt='Contents' width='
32'
/></A></td>
<td class='online-navigation'
><img src='../icons/blank.png'
border='
0' height='
32' alt='' width='
32'
/></td>
<td class='online-navigation'
><img src='../icons/blank.png'
border='
0' height='
32' alt='' width='
32'
/></td>
<div class='online-navigation'
>
<b class=
"navlabel">Previous:
</b>
<a class=
"sectref" rel=
"prev" href=
"node10.html">9 PEP
328: Multi-line
</A>
<b class=
"navlabel">Up:
</b>
<a class=
"sectref" rel=
"parent" href=
"whatsnew24.html">What's New in Python
</A>
<b class=
"navlabel">Next:
</b>
<a class=
"sectref" rel=
"next" href=
"node12.html">11 Other Language Changes
</A>
<!--End of Navigation Panel-->
<H1><A NAME=
"SECTION0001100000000000000000">
10 PEP
331: Locale-Independent Float/String Conversions
</A>
The
<tt class=
"module">locale
</tt> modules lets Python software select various
conversions and display conventions that are localized to a particular
country or language. However, the module was careful to not change
the numeric locale because various functions in Python's
implementation required that the numeric locale remain set to the
<code>'C'
</code> locale. Often this was because the code was using the C library's
<tt class=
"cfunction">atof()
</tt> function.
Not setting the numeric locale caused trouble for extensions that used
third-party C libraries, however, because they wouldn't have the
correct locale set. The motivating example was GTK+, whose user
interface widgets weren't displaying numbers in the current locale.
The solution described in the PEP is to add three new functions to the
Python API that perform ASCII-only conversions, ignoring the locale
<LI><tt class=
"cfunction">PyOS_ascii_strtod(
<var>str
</var>,
<var>ptr
</var>)
</tt>
and
<tt class=
"cfunction">PyOS_ascii_atof(
<var>str
</var>,
<var>ptr
</var>)
</tt>
both convert a string to a C
<tt class=
"ctype">double
</tt>.
<LI><tt class=
"cfunction">PyOS_ascii_formatd(
<var>buffer
</var>,
<var>buf_len
</var>,
<var>format
</var>,
<var>d
</var>)
</tt> converts a
<tt class=
"ctype">double
</tt> to an ASCII string.
The code for these functions came from the GLib library
(
<a class=
"url" href=
"http://developer.gnome.org/arch/gtk/glib.html">http://developer.gnome.org/arch/gtk/glib.html
</a>), whose
developers kindly relicensed the relevant functions and donated them
to the Python Software Foundation. The
<tt class=
"module">locale
</tt> module
can now change the numeric locale, letting extensions such as GTK+
produce the correct results.
<p class=
"heading">See Also:
</p>
<dl compact=
"compact" class=
"seerfc">
<dt><a href=
"http://www.python.org/peps/pep-0331.html"
title=
"Locale-Independent Float/String Conversions"
>PEP
331,
<em>Locale-Independent Float/String Conversions
</em></a>
<dd>Written by Christian R. Reis, and implemented by Gustavo Carneiro.
<div class='online-navigation'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"9 PEP 328: Multi-line"
href=
"node10.html"><img src='../icons/previous.png'
border='
0' height='
32' alt='Previous Page' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"parent" title=
"What's New in Python"
href=
"whatsnew24.html"><img src='../icons/up.png'
border='
0' height='
32' alt='Up One Level' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"next" title=
"11 Other Language Changes"
href=
"node12.html"><img src='../icons/next.png'
border='
0' height='
32' alt='Next Page' width='
32'
/></A></td>
<td align=
"center" width=
"100%">What's New in Python
2.4</td>
<td class='online-navigation'
><a rel=
"contents" title=
"Table of Contents"
href=
"contents.html"><img src='../icons/contents.png'
border='
0' height='
32' alt='Contents' width='
32'
/></A></td>
<td class='online-navigation'
><img src='../icons/blank.png'
border='
0' height='
32' alt='' width='
32'
/></td>
<td class='online-navigation'
><img src='../icons/blank.png'
border='
0' height='
32' alt='' width='
32'
/></td>
<div class='online-navigation'
>
<b class=
"navlabel">Previous:
</b>
<a class=
"sectref" rel=
"prev" href=
"node10.html">9 PEP
328: Multi-line
</A>
<b class=
"navlabel">Up:
</b>
<a class=
"sectref" rel=
"parent" href=
"whatsnew24.html">What's New in Python
</A>
<b class=
"navlabel">Next:
</b>
<a class=
"sectref" rel=
"next" href=
"node12.html">11 Other Language Changes
</A>
<span class=
"release-info">Release
1.01.
</span>
<!--End of Navigation Panel-->
See
<i><a href=
"about.html">About this document...
</a></i> for information on suggesting changes.