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="whatsnew24.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="whatsnew24.html" title='What's New in Python 2.4' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='last' href='about.html' title='About this document...' /> | |
10 | <link rel='help' href='about.html' title='About this document...' /> | |
11 | <link rel="next" href="node12.html" /> | |
12 | <link rel="prev" href="node10.html" /> | |
13 | <link rel="parent" href="whatsnew24.html" /> | |
14 | <link rel="next" href="node12.html" /> | |
15 | <meta name='aesop' content='information' /> | |
16 | <title>10 PEP 331: Locale-Independent Float/String Conversions</title> | |
17 | </head> | |
18 | <body> | |
19 | <DIV CLASS="navigation"> | |
20 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
21 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
22 | <tr> | |
23 | <td class='online-navigation'><a rel="prev" title="9 PEP 328: Multi-line" | |
24 | href="node10.html"><img src='../icons/previous.png' | |
25 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
26 | <td class='online-navigation'><a rel="parent" title="What's New in Python" | |
27 | href="whatsnew24.html"><img src='../icons/up.png' | |
28 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
29 | <td class='online-navigation'><a rel="next" title="11 Other Language Changes" | |
30 | href="node12.html"><img src='../icons/next.png' | |
31 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
32 | <td align="center" width="100%">What's New in Python 2.4</td> | |
33 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
34 | href="contents.html"><img src='../icons/contents.png' | |
35 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
36 | <td class='online-navigation'><img src='../icons/blank.png' | |
37 | border='0' height='32' alt='' width='32' /></td> | |
38 | <td class='online-navigation'><img src='../icons/blank.png' | |
39 | border='0' height='32' alt='' width='32' /></td> | |
40 | </tr></table> | |
41 | <div class='online-navigation'> | |
42 | <b class="navlabel">Previous:</b> | |
43 | <a class="sectref" rel="prev" href="node10.html">9 PEP 328: Multi-line</A> | |
44 | <b class="navlabel">Up:</b> | |
45 | <a class="sectref" rel="parent" href="whatsnew24.html">What's New in Python</A> | |
46 | <b class="navlabel">Next:</b> | |
47 | <a class="sectref" rel="next" href="node12.html">11 Other Language Changes</A> | |
48 | </div> | |
49 | <hr /></div> | |
50 | </DIV> | |
51 | <!--End of Navigation Panel--> | |
52 | ||
53 | <H1><A NAME="SECTION0001100000000000000000"> | |
54 | 10 PEP 331: Locale-Independent Float/String Conversions</A> | |
55 | </H1> | |
56 | ||
57 | <P> | |
58 | The <tt class="module">locale</tt> modules lets Python software select various | |
59 | conversions and display conventions that are localized to a particular | |
60 | country or language. However, the module was careful to not change | |
61 | the numeric locale because various functions in Python's | |
62 | implementation required that the numeric locale remain set to the | |
63 | <code>'C'</code> locale. Often this was because the code was using the C library's | |
64 | <tt class="cfunction">atof()</tt> function. | |
65 | ||
66 | <P> | |
67 | Not setting the numeric locale caused trouble for extensions that used | |
68 | third-party C libraries, however, because they wouldn't have the | |
69 | correct locale set. The motivating example was GTK+, whose user | |
70 | interface widgets weren't displaying numbers in the current locale. | |
71 | ||
72 | <P> | |
73 | The solution described in the PEP is to add three new functions to the | |
74 | Python API that perform ASCII-only conversions, ignoring the locale | |
75 | setting: | |
76 | ||
77 | <P> | |
78 | ||
79 | <UL> | |
80 | <LI><tt class="cfunction">PyOS_ascii_strtod(<var>str</var>, <var>ptr</var>)</tt> | |
81 | and <tt class="cfunction">PyOS_ascii_atof(<var>str</var>, <var>ptr</var>)</tt> | |
82 | both convert a string to a C <tt class="ctype">double</tt>. | |
83 | </LI> | |
84 | <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. | |
85 | </LI> | |
86 | </UL> | |
87 | ||
88 | <P> | |
89 | The code for these functions came from the GLib library | |
90 | (<a class="url" href="http://developer.gnome.org/arch/gtk/glib.html">http://developer.gnome.org/arch/gtk/glib.html</a>), whose | |
91 | developers kindly relicensed the relevant functions and donated them | |
92 | to the Python Software Foundation. The <tt class="module">locale</tt> module | |
93 | can now change the numeric locale, letting extensions such as GTK+ | |
94 | produce the correct results. | |
95 | ||
96 | <P> | |
97 | <div class="seealso"> | |
98 | <p class="heading">See Also:</p> | |
99 | ||
100 | <dl compact="compact" class="seerfc"> | |
101 | <dt><a href="http://www.python.org/peps/pep-0331.html" | |
102 | title="Locale-Independent Float/String Conversions" | |
103 | >PEP 331, <em>Locale-Independent Float/String Conversions</em></a> | |
104 | <dd>Written by Christian R. Reis, and implemented by Gustavo Carneiro. | |
105 | </dl> | |
106 | </div> | |
107 | ||
108 | <P> | |
109 | ||
110 | <DIV CLASS="navigation"> | |
111 | <div class='online-navigation'> | |
112 | <p></p><hr /> | |
113 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
114 | <tr> | |
115 | <td class='online-navigation'><a rel="prev" title="9 PEP 328: Multi-line" | |
116 | href="node10.html"><img src='../icons/previous.png' | |
117 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
118 | <td class='online-navigation'><a rel="parent" title="What's New in Python" | |
119 | href="whatsnew24.html"><img src='../icons/up.png' | |
120 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
121 | <td class='online-navigation'><a rel="next" title="11 Other Language Changes" | |
122 | href="node12.html"><img src='../icons/next.png' | |
123 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
124 | <td align="center" width="100%">What's New in Python 2.4</td> | |
125 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
126 | href="contents.html"><img src='../icons/contents.png' | |
127 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
128 | <td class='online-navigation'><img src='../icons/blank.png' | |
129 | border='0' height='32' alt='' width='32' /></td> | |
130 | <td class='online-navigation'><img src='../icons/blank.png' | |
131 | border='0' height='32' alt='' width='32' /></td> | |
132 | </tr></table> | |
133 | <div class='online-navigation'> | |
134 | <b class="navlabel">Previous:</b> | |
135 | <a class="sectref" rel="prev" href="node10.html">9 PEP 328: Multi-line</A> | |
136 | <b class="navlabel">Up:</b> | |
137 | <a class="sectref" rel="parent" href="whatsnew24.html">What's New in Python</A> | |
138 | <b class="navlabel">Next:</b> | |
139 | <a class="sectref" rel="next" href="node12.html">11 Other Language Changes</A> | |
140 | </div> | |
141 | </div> | |
142 | <hr /> | |
143 | <span class="release-info">Release 1.01.</span> | |
144 | </DIV> | |
145 | <!--End of Navigation Panel--> | |
146 | <ADDRESS> | |
147 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
148 | </ADDRESS> | |
149 | </BODY> | |
150 | </HTML> |