Add %pythonbegin directive.
For adding code at the beginning of the generated .py file.
This commit is contained in:
parent
eb98c0be99
commit
d0af4f50d3
5 changed files with 71 additions and 3 deletions
|
|
@ -3314,6 +3314,53 @@ what can be done without having to rely on any of the more advanced
|
|||
customization features.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
There is also <tt>%pythonbegin</tt> which is another directive very similar to <tt>%pythoncode</tt>,
|
||||
but generates the given Python code at the beginning of the <tt>.py</tt> file.
|
||||
This directive works in the same way as <tt>%pythoncode</tt>, except the code is copied
|
||||
just after the SWIG banner (comment) at the top of the file, before any real code.
|
||||
This provides an opportunity to add your own description in a comment near the top of the file as well
|
||||
as Python imports that have to appear at the top of the file, such as "<tt>from __future__ import</tt>"
|
||||
statements.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The following shows example usage for Python 2.6 to use <tt>print</tt> as it can in Python 3, that is, as a function instead of a statement:
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>
|
||||
%pythonbegin %{
|
||||
# This module provides wrappers to the Whizz Bang library
|
||||
%}
|
||||
|
||||
%pythonbegin %{
|
||||
from __future__ import print_function
|
||||
print("Loading", "Whizz", "Bang", sep=' ... ')
|
||||
%}
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
which can be seen when viewing the first few lines of the generated <tt>.py</tt> file:
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>
|
||||
# This file was automatically generated by SWIG (http://www.swig.org).
|
||||
# Version 2.0.11
|
||||
#
|
||||
# Do not make changes to this file unless you know what you are doing--modify
|
||||
# the SWIG interface file instead.
|
||||
|
||||
# This module provides wrappers to the Whizz Bang library
|
||||
|
||||
from __future__ import print_function
|
||||
print("Loading", "Whizz", "Bang", sep=' ... ')
|
||||
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>Sometimes you may want to replace or modify the wrapper function
|
||||
that SWIG creates in the proxy <tt>.py</tt> file. The Python module
|
||||
in SWIG provides some features that enable you to do this. First, to
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue