MissingPy-0.10.5: Haskell interface to Python

MaintainerJohn Goerzen,

Python.Objects

Contents

Description

Maintainer : jgoerzen@complete.org Stability : provisional Portability: portable

Python type instances and object utilities.

For more similar utilities, see Python.Objects.File and Python.Objects.Dict.

Written by John Goerzen, jgoerzen@complete.org

Synopsis

Basic Object Types

data PyObject Source

The type of Python objects.

Instances

Eq PyObject 
Show PyObject 
FromPyObject a => FromPyObject [(a, PyObject)] 
FromPyObject [(PyObject, PyObject)]

ALs from Dicts

FromPyObject [PyObject]

Tuples and Lists to [PyObject] lists

ToPyObject a => ToPyObject [(a, PyObject)]

This is a common variant used for arg lists

ToPyObject [(PyObject, PyObject)]

Dicts from ALs

ToPyObject [PyObject]

Lists from a PyObject

Conversions between Haskell and Python Objects

class ToPyObject a whereSource

Members of this class can be converted from a Haskell type to a Python object.

Instances

ToPyObject Integer 
ToPyObject String 
ToPyObject CStringLen 
ToPyObject CInt 
ToPyObject CLong 
ToPyObject CDouble 
(ToPyObject a, ToPyObject b) => ToPyObject [(a, b)]

Dicts from Haskell objects

ToPyObject a => ToPyObject [(a, PyObject)]

This is a common variant used for arg lists

ToPyObject [(PyObject, PyObject)]

Dicts from ALs

ToPyObject a => ToPyObject [a]

Lists from anything else

ToPyObject [PyObject]

Lists from a PyObject

class FromPyObject a whereSource

Members of this class can be derived from a Python object.

Instances

Information about Python Objects

typeOf :: PyObject -> IO PyObjectSource

Gets the type of a Python object. Same as type(x) in Python.

strOf :: PyObject -> IO StringSource

Gets a string representation of a Python object. Same as str(x) in Python.

reprOf :: PyObject -> IO StringSource

Gets the Python representation of a Python object. Same as repr(x) in Python.

showPyObject :: PyObject -> IO StringSource

Displays a Python object and its type.

dirPyObject :: PyObject -> IO [String]Source

Displays a list of keys contained in the Python object.

getattr :: PyObject -> String -> IO PyObjectSource

An interface to a function similar to Python's getattr. This will look up an attribute (such as a method) of an object.

hasattr :: PyObject -> String -> IO BoolSource

An interface to Python's hasattr. Returns True if the named attribute exists; False otherwise.

setattrSource

Arguments

:: PyObject

Object to operate on

-> String

Name of attribute

-> PyObject

Set the attribute to this value

-> IO () 

An interface to Python's setattr, used to set attributes of an object.

Conversions between Python Objects

Calling Python Objects

pyObject_CallSource

Arguments

:: PyObject

Object to call

-> [PyObject]

List of non-keyword parameters (may be empty)

-> [(String, PyObject)]

List of keyword parameters (may be empty)

-> IO PyObject

Return value

Call a Python object (function, etc).

For a higher-level wrapper, see Python.Interpreter.callByName.

Converts a Python list to a tuple.

pyObject_CallHsSource

Arguments

:: (ToPyObject a, ToPyObject b, FromPyObject c) 
=> PyObject

Object t

-> [a]

List of non-keyword parameters

-> [(String, b)]

List of keyword parameters

-> IO c

Return value

Call a Python object with all-Haskell parameters. Similar to PyObject_Call. This limits you to a single item type for the regular arguments and another single item type for the keyword arguments. Nevertheless, it could be a handy shortcut at times.

For a higher-level wrapper, see Python.Interpreter.callByName.

You may find noParms and noKwParms useful if you aren't passing any parameters.

pyObject_RunHsSource

Arguments

:: (ToPyObject a, ToPyObject b) 
=> PyObject

Object t

-> [a]

List of non-keyword parameters

-> [(String, b)]

List of keyword parameters

-> IO ()

Return value

Like PyObject_CallHs, but discards the return value.

callMethodHsSource

Arguments

:: (ToPyObject a, ToPyObject b, FromPyObject c) 
=> PyObject

The main object

-> String

Name of method to call

-> [a]

Non-kw args

-> [(String, b)]

Keyword args

-> IO c

Result

Calls the named method of the given object.

runMethodHsSource

Arguments

:: (ToPyObject a, ToPyObject b) 
=> PyObject

The main object

-> String

Name of method to call

-> [a]

Non-kw args

-> [(String, b)]

Keyword args

-> IO ()

Result

Like callMethodHs, but discards the return value.