Python - Encapuslate python objects |
Python - Encapuslate python objects
use Python qw(getattr list);
# constructors $list = list(1..10);
# accessor if (my $foo = getattr($o, "foo")) { # ... }
Python
is an interpreted, interactive, object-oriented programming
language programming language created by Guido van Rossum
(www.python.org). This manpage describe the perl interface to python
data managed by an embedded Python interpreter.
The Python::
namespace contain various functions to construct,
modify and examine python objects. Python objects themselves are
wrapped up in instances of the perl class Python::Object
.
The following object constructor functions are provided. They all
return Python::Object
instances. Usually one will not have to
construct Python::Object
s directly since they are constructed
implicitly when python data is passed to perl either as perl function
arguments or as the return values from calls into python.
object()
constructor will first make a python object of whatever
perl data is passed in and then return a Python::Object wrapper for
it. A call like:
$o = object("$something")
will make sure you produce a string object.
The following functions with mostly identical behaviour to the
corresponding python builtins are available. These functions will
croak if the $o argument is not a Python::Object
instance.
id($o)
hash($o)
len($o)
type($o)
str($o)
Overloaded as perl stringify operator.
repr($o)
Python::Err
namespace. E.g.:
Python::raise(Python::Err::TypeError, "'foo' wanted here");
The following functions that map the Python internal C API are made available.
setitem()
and delitem()
after the pattern
established by the corresponding {get,set,del}attr() calls.
PyObject_IsTrue($o)
Overloaded as boolean test operator.
The following functions determine if the object is of the given type.
If $o is not a reference to a Python::Object
instance, then these
all return FALSE.
PyCallable_Check($o)
PySequence_Check($o)
PyMapping_Check($o)
(C) 2000-2001 ActiveState
This code is distributed under the same terms as Perl; you can redistribute it and/or modify it under the terms of either the GNU General Public License or the Artistic License.
THIS SOFTWARE IS PROVIDED BY ACTIVESTATE `AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ACTIVESTATE OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
python, the perl manpage, the Python::Object manpage, the Python::Err manpage, perlmodule
Python - Encapuslate python objects |