diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2013-07-05 06:30:16 +0100 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2013-07-05 06:30:16 +0100 |
commit | d0af4f50d301cd971e7dadf1e48a5b5c8c66e4b4 (patch) | |
tree | 4787494eb1d212ccaac7a36e05e17d5750bb936f /Doc/Manual | |
parent | eb98c0be99a3da4ea860a5068e067459d472a658 (diff) | |
download | swig-d0af4f50d301cd971e7dadf1e48a5b5c8c66e4b4.tar.gz |
Add %pythonbegin directive.
For adding code at the beginning of the generated .py file.
Diffstat (limited to 'Doc/Manual')
-rw-r--r-- | Doc/Manual/Python.html | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index 3dde20887..6a22738bc 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -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 |