|
43 | 43 | But before you do, you might want to fire up Python 2.2 or later and type |
44 | 44 | <tt class="literal">>>> import this</tt>.</p> |
45 | 45 | <pre class="programlisting"><tt class="literal">>>> import this |
46 | | - The Zen of Python, by Tim Peters |
47 | | - Beautiful is better than ugly. |
48 | | - Explicit is better than implicit. |
49 | | - Simple is better than complex. |
50 | | - Complex is better than complicated. |
51 | | - Flat is better than nested. |
52 | | - Sparse is better than dense. |
53 | | - Readability counts. |
54 | | - Special cases aren't special enough to break the rules. |
55 | | - Although practicality beats purity. |
56 | | - Errors should never pass silently. |
57 | | - Unless explicitly silenced. |
58 | | - In the face of ambiguity, refuse the temptation to guess. |
59 | | - There should be one-- and preferably only one --obvious way to do it |
60 | | - Although that way may not be obvious at first unless you're Dutch. |
61 | | - Now is better than never. |
62 | | - Although never is often better than <span class="bold"><b>right</b></span> now. |
63 | | - If the implementation is hard to explain, it's a bad idea. |
64 | | - If the implementation is easy to explain, it may be a good idea. |
65 | | - Namespaces are one honking great idea -- let's do more of those! |
| 46 | +The Zen of Python, by Tim Peters |
| 47 | +Beautiful is better than ugly. |
| 48 | +Explicit is better than implicit. |
| 49 | +Simple is better than complex. |
| 50 | +Complex is better than complicated. |
| 51 | +Flat is better than nested. |
| 52 | +Sparse is better than dense. |
| 53 | +Readability counts. |
| 54 | +Special cases aren't special enough to break the rules. |
| 55 | +Although practicality beats purity. |
| 56 | +Errors should never pass silently. |
| 57 | +Unless explicitly silenced. |
| 58 | +In the face of ambiguity, refuse the temptation to guess. |
| 59 | +There should be one-- and preferably only one --obvious way to do it |
| 60 | +Although that way may not be obvious at first unless you're Dutch. |
| 61 | +Now is better than never. |
| 62 | +Although never is often better than <span class="bold"><b>right</b></span> now. |
| 63 | +If the implementation is hard to explain, it's a bad idea. |
| 64 | +If the implementation is easy to explain, it may be a good idea. |
| 65 | +Namespaces are one honking great idea -- let's do more of those! |
66 | 66 | </tt></pre> |
67 | 67 | <div class="section" lang="en"> |
68 | 68 | <div class="titlepage"><div><div><h3 class="title"> |
|
174 | 174 | <li><span class="bold"><b>BOOM!</b></span></li> |
175 | 175 | </ol></div> |
176 | 176 | <a name="call_policies.call_policies"></a><h2> |
177 | | -<a name="id454356"></a>Call Policies</h2> |
| 177 | +<a name="id454278"></a>Call Policies</h2> |
178 | 178 | <p> |
179 | 179 | Call Policies may be used in situations such as the example detailed above. |
180 | 180 | In our example, <tt class="literal">return_internal_reference</tt> and <tt class="literal">with_custodian_and_ward</tt> |
|
336 | 336 | </li> |
337 | 337 | </ul></div> |
338 | 338 | <a name="default_arguments.boost_python_function_overloads"></a><h2> |
339 | | -<a name="id456178"></a>BOOST_PYTHON_FUNCTION_OVERLOADS</h2> |
| 339 | +<a name="id456100"></a>BOOST_PYTHON_FUNCTION_OVERLOADS</h2> |
340 | 340 | <p> |
341 | 341 | Boost.Python now has a way to make it easier. For instance, given a function:</p> |
342 | 342 | <pre class="programlisting"><tt class="literal"><span class="keyword">int</span><span class="identifier"> foo</span><span class="special">(</span><span class="keyword">int</span><span class="identifier"> a</span><span class="special">,</span><span class="keyword"> char</span><span class="identifier"> b</span><span class="special"> =</span><span class="number"> 1</span><span class="special">,</span><span class="keyword"> unsigned</span><span class="identifier"> c</span><span class="special"> =</span><span class="number"> 2</span><span class="special">,</span><span class="keyword"> double</span><span class="identifier"> d</span><span class="special"> =</span><span class="number"> 3</span><span class="special">)</span><span class="special"> |
|
355 | 355 | automatically add all the foo variants for us:</p> |
356 | 356 | <pre class="programlisting"><tt class="literal"><span class="identifier">def</span><span class="special">(</span><span class="string">"foo"</span><span class="special">,</span><span class="identifier"> foo</span><span class="special">,</span><span class="identifier"> foo_overloads</span><span class="special">());</span></tt></pre> |
357 | 357 | <a name="default_arguments.boost_python_member_function_overloads"></a><h2> |
358 | | -<a name="id456457"></a>BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</h2> |
| 358 | +<a name="id456379"></a>BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS</h2> |
359 | 359 | <p> |
360 | 360 | Objects here, objects there, objects here there everywhere. More frequently |
361 | 361 | than anything else, we need to expose member functions of our classes to |
|
387 | 387 | See the <a href="../../../../v2/overloads.html#BOOST_PYTHON_FUNCTION_OVERLOADS-spec" target="_top">overloads reference</a> |
388 | 388 | for details.</p> |
389 | 389 | <a name="default_arguments.init_and_optional"></a><h2> |
390 | | -<a name="id456784"></a>init and optional</h2> |
| 390 | +<a name="id456707"></a>init and optional</h2> |
391 | 391 | <p> |
392 | 392 | A similar facility is provided for class constructors, again, with |
393 | 393 | default arguments or a sequence of overloads. Remember <tt class="literal">init<...></tt>? For example, |
|
442 | 442 | Notice though that we have a situation now where we have a minimum of zero |
443 | 443 | (0) arguments and a maximum of 3 arguments.</p> |
444 | 444 | <a name="auto_overloading.manual_wrapping"></a><h2> |
445 | | -<a name="id457431"></a>Manual Wrapping</h2> |
| 445 | +<a name="id457353"></a>Manual Wrapping</h2> |
446 | 446 | <p> |
447 | 447 | It is important to emphasize however that <span class="bold"><b>the overloaded functions must |
448 | 448 | have a common sequence of initial arguments</b></span>. Otherwise, our scheme above |
|
0 commit comments